Skip to content

A free open source IT asset/license management system

The return early pattern applied to improve readability. (#8894)

Serkan0e34e43abbe2
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php
index a237775428..fc6c23228e 100644
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@ -1003,38 +1003,38 @@ class Helper
* @return string path to uploaded image or false if something went wrong
*/
public static function processUploadedImage(String $image_data, String $save_path) {
- if ($image_data != null && $save_path != null) {
- // After modification, the image is prefixed by mime info like the following:
- // data:image/jpeg;base64,; This causes the image library to be unhappy, so we need to remove it.
- $header = explode(';', $image_data, 2)[0];
- // Grab the image type from the header while we're at it.
- $extension = substr($header, strpos($header, '/')+1);
- // Start reading the image after the first comma, postceding the base64.
- $image = substr($image_data, strpos($image_data, ',')+1);
-
- $file_name = str_random(25).".".$extension;
-
- $directory= public_path($save_path);
- // Check if the uploads directory exists. If not, try to create it.
- if (!file_exists($directory)) {
- mkdir($directory, 0755, true);
- }
+ if ($image_data == null || $save_path == null) {
+ return false;
+ }
- $path = public_path($save_path.$file_name);
+ // After modification, the image is prefixed by mime info like the following:
+ // data:image/jpeg;base64,; This causes the image library to be unhappy, so we need to remove it.
+ $header = explode(';', $image_data, 2)[0];
+ // Grab the image type from the header while we're at it.
+ $extension = substr($header, strpos($header, '/')+1);
+ // Start reading the image after the first comma, postceding the base64.
+ $image = substr($image_data, strpos($image_data, ',')+1);
- try {
- Image::make($image)->resize(500, 500, function ($constraint) {
- $constraint->aspectRatio();
- $constraint->upsize();
- })->save($path);
- } catch (\Exception $e) {
- return false;
- }
+ $file_name = str_random(25).".".$extension;
- return $file_name;
+ $directory= public_path($save_path);
+ // Check if the uploads directory exists. If not, try to create it.
+ if (!file_exists($directory)) {
+ mkdir($directory, 0755, true);
}
- return false;
+ $path = public_path($save_path.$file_name);
+
+ try {
+ Image::make($image)->resize(500, 500, function ($constraint) {
+ $constraint->aspectRatio();
+ $constraint->upsize();
+ })->save($path);
+ } catch (\Exception $e) {
+ return false;
+ }
+
+ return $file_name;
}
}