From 8de5aaebebb1d56eb6ec4e9c6c43d3b6f61be29c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 14 Mar 2022 04:04:33 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Traits/Thumbnail.php | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Traits/Thumbnail.php b/src/Traits/Thumbnail.php index 79ee13a..f99ff69 100644 --- a/src/Traits/Thumbnail.php +++ b/src/Traits/Thumbnail.php @@ -4,13 +4,13 @@ use Carbon\Carbon; use Illuminate\Support\Facades\File; -use Intervention\Image\Facades\Image as Image; +use Intervention\Image\Facades\Image; trait Thumbnail { public function makeThumbnail($fieldname = 'image', $custom = []) { - if (!empty(request()->$fieldname) || $custom['image']) { + if (! empty(request()->$fieldname) || $custom['image']) { /* ------------------------------------------------------------------- */ $image_file = $custom['image'] ?? request()->file($fieldname); // Retriving Image File @@ -29,7 +29,7 @@ public function makeThumbnail($fieldname = 'image', $custom = []) if ($thumbnails) { /* -----------------------------------------Custom Thumbnails------------------------------------------------- */ $this->makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails); - /* -------------------------------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------------------------------- */ } else { /* ---------------------------------------Default Thumbnails--------------------------------------- */ $this->makeDefaultThumbnails($image_file, $extension, $imageStoreNameOnly); @@ -46,14 +46,14 @@ private function makeImg($image_file, $name, $location, $width, $height, $qualit $img = Image::cache(function ($cached_img) use ($image_file, $width, $height) { return $cached_img->make($image_file->getRealPath())->fit($width, $height); }, config('thumbnail.image_cached_time', 10), true); //Storing Thumbnail - $img->save(public_path('storage/' . $image), $quality); //Storing Thumbnail + $img->save(public_path('storage/'.$image), $quality); //Storing Thumbnail } // Make Custom Thumbnail private function makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails) { foreach ($thumbnails as $thumbnail) { - $customthumbnail = $imageStoreNameOnly . '-' . str_replace('-', '', $thumbnail['thumbnail-name']) . '.' . $extension; // Making Thumbnail Name + $customthumbnail = $imageStoreNameOnly.'-'.str_replace('-', '', $thumbnail['thumbnail-name']).'.'.$extension; // Making Thumbnail Name $this->makeImg( $image_file, $customthumbnail, @@ -70,10 +70,10 @@ private function makeDefaultThumbnails($image_file, $extension, $imageStoreNameO { /* --------------------- Thumbnail Info---------------------------------------- */ //small thumbnail name - $smallthumbnail = $imageStoreNameOnly . '-small' . '.' . $extension; // Making Thumbnail Name + $smallthumbnail = $imageStoreNameOnly.'-small'.'.'.$extension; // Making Thumbnail Name //medium thumbnail name - $mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name + $mediumthumbnail = $imageStoreNameOnly.'-medium'.'.'.$extension; // Making Thumbnail Name // Medium Thumbnail $this->makeImg( @@ -103,10 +103,10 @@ private function image_info($image_file) { $filenamewithextension = $image_file->getClientOriginalName(); //Retriving Full Image Name $raw_filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); //Retriving Image Raw Filename only - $filename = $this->validImageName($raw_filename);; // Retrive Filename + $filename = $this->validImageName($raw_filename); // Retrive Filename $extension = $image_file->getClientOriginalExtension(); //Retriving Image extension - $imageStoreNameOnly = $filename . '-' . time(); //Making Image Store name - $imageStoreName = $filename . '-' . time() . '.' . $extension; //Making Image Store name + $imageStoreNameOnly = $filename.'-'.time(); //Making Image Store name + $imageStoreName = $filename.'-'.time().'.'.$extension; //Making Image Store name $image_info['filenamewithextension'] = $filenamewithextension; $image_info['raw_filename'] = $raw_filename; @@ -131,7 +131,7 @@ public function uploadImage($fieldname = 'image', $custom = []) $image = Image::cache(function ($cached_img) use ($image_file, $custom) { return $cached_img->make($image_file->getRealPath())->fit($custom['width'] ?? config('thumbnail.img_width', 1000), $custom['height'] ?? config('thumbnail.img_height', 800)); //Parent Image Interventing }, config('thumbnail.image_cached_time', 10), true); - $image->save(public_path('storage/' . $this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save + $image->save(public_path('storage/'.$this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save } // Thumbnail Path @@ -165,12 +165,12 @@ public function imageDetail($fieldname = 'image', $size = null, $byLocation = fa $image = $byLocation ? ($location ?? $this->$fieldname) : $this->$fieldname; // Search By Field or Location $path = explode('/', $image); $extension = \File::extension($image); - $name = basename($image, '.' . $extension); - $image_fullname = isset($size) ? $name . '-' . (string) $size . '.' . $extension : $name . '.' . $extension; + $name = basename($image, '.'.$extension); + $image_fullname = isset($size) ? $name.'-'.(string) $size.'.'.$extension : $name.'.'.$extension; array_pop($path); $location = implode('/', $path); - $path = 'storage/' . $location . '/' . $image_fullname; - $image_files = File::files(public_path('storage/' . $location)); + $path = 'storage/'.$location.'/'.$image_fullname; + $image_files = File::files(public_path('storage/'.$location)); $images_property = $this->imageProperty($image_files, $name); $image_detail = [ 'image' => $image, @@ -178,8 +178,8 @@ public function imageDetail($fieldname = 'image', $size = null, $byLocation = fa 'fullname' => $image_fullname, 'extension' => $extension, 'path' => $path, - 'directory' => public_path('storage/' . $location), - 'location' => public_path('storage/' . $image), + 'directory' => public_path('storage/'.$location), + 'location' => public_path('storage/'.$image), 'property' => $images_property, ]; @@ -199,7 +199,7 @@ private function imageProperty($image_files, $parent_name) $image_partition = explode('-', basename($image)); if (isset($image_partition[0]) && isset($image_partition[1])) { - $parent_thumbnail_name = $image_partition[0] . '-' . $image_partition[1]; + $parent_thumbnail_name = $image_partition[0].'-'.$image_partition[1]; if ($parent_name == $parent_thumbnail_name) { $thumbnail_count++; $thumbnail_exists = $this->imageExists($image); @@ -221,7 +221,8 @@ private function imageProperty($image_files, $parent_name) $images_property['size'] = $image->getSize(); $images_property['directory'] = $image->getPath(); $images_property['location'] = $image->getRealPath(); - } else { } + } else { + } } } @@ -251,6 +252,6 @@ public function hardDeleteWithParent($fieldname = 'image'): void // Valid Image Name private function validImageName($name) { - return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':' . ';', ',', "'", '"'], '_', trim($name))); + return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':'.';', ',', "'", '"'], '_', trim($name))); } }