From 46185a6d4487bd7717f6c2f943c286d36f2d693c Mon Sep 17 00:00:00 2001 From: Ollama Date: Thu, 12 Mar 2026 19:44:38 +0000 Subject: [PATCH] Address review feedback: use ternary, camelCase, remove test file - Use ternary notation for $images assignment in getPicThumb - Refactor local variables to camelCase for PSR-12 compliance - Remove test_avatar_toggle.html from repository --- app/Controllers/Items.php | 41 +++++++------ app/Helpers/tabular_helper.php | 12 ++-- test_avatar_toggle.html | 101 --------------------------------- 3 files changed, 25 insertions(+), 129 deletions(-) delete mode 100644 test_avatar_toggle.html diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 99de66617..e59fd709b 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -167,48 +167,45 @@ class Items extends Secure_Controller { helper('file'); - $file_extension = pathinfo($pic_filename, PATHINFO_EXTENSION); - $upload_path = FCPATH . 'uploads/item_pics/'; + $fileExtension = pathinfo($pic_filename, PATHINFO_EXTENSION); + $uploadPath = FCPATH . 'uploads/item_pics/'; - // Handle files with and without extensions - if (empty($file_extension)) { - $images = glob($upload_path . $pic_filename . '.*'); - } else { - $images = glob($upload_path . $pic_filename); - } + $images = empty($fileExtension) + ? glob($uploadPath . $pic_filename . '.*') + : glob($uploadPath . $pic_filename); if (sizeof($images) > 0) { - $image_path = $images[0]; - $actual_extension = pathinfo($image_path, PATHINFO_EXTENSION); - $base_path = $upload_path . pathinfo($pic_filename, PATHINFO_FILENAME); - $thumb_path = $base_path . "_thumb.$actual_extension"; + $imagePath = $images[0]; + $actualExtension = pathinfo($imagePath, PATHINFO_EXTENSION); + $basePath = $uploadPath . pathinfo($pic_filename, PATHINFO_FILENAME); + $thumbPath = $basePath . "_thumb.$actualExtension"; // Try to create thumbnail if it doesn't exist - if (!file_exists($thumb_path)) { + if (!file_exists($thumbPath)) { try { $image = Services::image('gd2'); - $image->withFile($image_path) + $image->withFile($imagePath) ->resize(52, 32, true, 'height') - ->save($thumb_path); + ->save($thumbPath); } catch (Exception $e) { // If thumbnail creation fails, serve original image log_message('error', 'Thumbnail creation failed: ' . $e->getMessage()); - $this->serveImage($image_path); + $this->serveImage($imagePath); return; } } // Serve thumbnail if it exists, otherwise serve original - if (file_exists($thumb_path)) { - $this->serveImage($thumb_path); + if (file_exists($thumbPath)) { + $this->serveImage($thumbPath); } else { - $this->serveImage($image_path); + $this->serveImage($imagePath); } } else { // No image found, serve default - $default_image = FCPATH . 'public/images/no-img.png'; - if (file_exists($default_image)) { - $this->serveImage($default_image); + $defaultImage = FCPATH . 'public/images/no-img.png'; + if (file_exists($defaultImage)) { + $this->serveImage($defaultImage); } else { // Return 404 if no default image $this->response->setStatusCode(404); diff --git a/app/Helpers/tabular_helper.php b/app/Helpers/tabular_helper.php index 9f009f183..731f82535 100644 --- a/app/Helpers/tabular_helper.php +++ b/app/Helpers/tabular_helper.php @@ -464,24 +464,24 @@ function get_item_data_row(object $item): array $image = ''; if (!empty($item->pic_filename)) { - $upload_path = FCPATH . 'uploads/item_pics/'; + $uploadPath = FCPATH . 'uploads/item_pics/'; $ext = pathinfo($item->pic_filename, PATHINFO_EXTENSION); // If no extension in filename, search for any file with that name if (empty($ext)) { - $pattern = $upload_path . $item->pic_filename . '.*'; + $pattern = $uploadPath . $item->pic_filename . '.*'; } else { - $pattern = $upload_path . $item->pic_filename; + $pattern = $uploadPath . $item->pic_filename; } $images = glob($pattern); if (!empty($images)) { - $rel_path = 'uploads/item_pics/' . basename($images[0]); + $relPath = 'uploads/item_pics/' . basename($images[0]); // Use direct image path instead of getPicThumb - $image = ' - + '; diff --git a/test_avatar_toggle.html b/test_avatar_toggle.html deleted file mode 100644 index 6efdbc83f..000000000 --- a/test_avatar_toggle.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - Avatar Toggle Test - - - - - -
-

Avatar Toggle Test

- - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
ImageDescriptionPriceQuantityTotal
- avatar - Test Item 1$10.002$20.00
- avatar - Test Item 2$15.001$15.00
-
-
- - - -