From 7abbb8a5aa5e9b5fb23e564f1db48509c779a92a Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Wed, 26 Aug 2026 01:08:03 -0700 Subject: [PATCH] stan fixes, code style fixes - all clean --- .gitignore | 1 + src/Controller/ProductCatalogsController.php | 19 +++++++++---------- .../ProductCategoriesController.php | 10 +++++----- .../ProductCategoryVariantsController.php | 2 +- src/Controller/ProductPhotosController.php | 18 +++++++++++++----- src/Controller/ProductVariantsController.php | 2 +- src/Controller/ProductsController.php | 9 ++++++--- src/Model/Entity/ProductCategoryVariant.php | 4 ++-- src/Model/Table/ProductCategoriesTable.php | 12 ++++++------ src/Model/Table/ProductPhotosTable.php | 2 +- 10 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 8f57e7f..86b5f92 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /.idea/ tmp tests/test_app/webroot/images/products/ +tests/test_app/webroot/uploads/ diff --git a/src/Controller/ProductCatalogsController.php b/src/Controller/ProductCatalogsController.php index 2469896..f119f9f 100644 --- a/src/Controller/ProductCatalogsController.php +++ b/src/Controller/ProductCatalogsController.php @@ -18,14 +18,12 @@ class ProductCatalogsController extends AppController { */ public function initialize(): void { parent::initialize(); // TODO: Change the autogenerated stub -// $this->_defaultTable = 'CakeProducts.ProductCatalogs'; -// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table'; } /** * Index method * - * @return \Cake\Http\Response|voidRenders|null view + * @return \Cake\Http\Response|null|void Renders view */ public function index() { $query = $this->ProductCatalogs->find(); @@ -38,8 +36,9 @@ class ProductCatalogsController extends AppController { * View method * * @param string|null $id Product Catalog id. - * @throws RecordNotFoundException When record not found. - * @return Response|null|void Renders view + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * + * @return \Cake\Http\Response|null|void Renders view */ public function view($id = null) { $contain = ['ProductCategories']; @@ -53,7 +52,7 @@ class ProductCatalogsController extends AppController { /** * Add method * - * @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise. + * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ public function add() { $productCatalogsTable = $this->ProductCatalogs; @@ -78,8 +77,8 @@ class ProductCatalogsController extends AppController { * Edit method * * @param string|null $id Product Catalog id. - * @throws RecordNotFoundException When record not found. - * @return Response|null|void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ public function edit($id = null) { $productCatalogsTable = $this->ProductCatalogs; @@ -100,8 +99,8 @@ class ProductCatalogsController extends AppController { * Delete method * * @param string|null $id Product Catalog id. - * @throws RecordNotFoundException When record not found. - * @return Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); diff --git a/src/Controller/ProductCategoriesController.php b/src/Controller/ProductCategoriesController.php index d44519a..79e5381 100644 --- a/src/Controller/ProductCategoriesController.php +++ b/src/Controller/ProductCategoriesController.php @@ -85,8 +85,8 @@ class ProductCategoriesController extends AppController { } $this->Flash->error(__('The product category could not be saved. Please, try again.')); } - $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all(); - $parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all(); + $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all(); + $parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all(); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); } @@ -145,14 +145,14 @@ class ProductCategoriesController extends AppController { * @return \Cake\Http\Response|null|void Renders view */ public function select() { - $this->ProductCategories->getBehavior('Tree')->setConfig([ + $this->ProductCategories->getBehavior('Tree')->setConfig([ 'scope' => [ 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), ], ]); $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? - $this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') : - $this->ProductCategories->find('treeList'); + $this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') : + $this->ProductCategories->find('treeList'); $productCategories = $productCategoriesQ ->orderBy(['ProductCategories.name']) diff --git a/src/Controller/ProductCategoryVariantsController.php b/src/Controller/ProductCategoryVariantsController.php index fc455cd..c2da378 100644 --- a/src/Controller/ProductCategoryVariantsController.php +++ b/src/Controller/ProductCategoryVariantsController.php @@ -122,7 +122,7 @@ class ProductCategoryVariantsController extends AppController { } $productCategories = $this->fetchTable('ProductCategories')->find('list', keyField: 'internal_id', valueField: 'name')->all(); $products = isset($productCategoryVariant->product_category_id) ? $this->fetchTable('Products')->find('list', limit: 200) - ->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; + ->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; $this->set(compact('productCategoryVariant', 'productCategories', 'products')); } diff --git a/src/Controller/ProductPhotosController.php b/src/Controller/ProductPhotosController.php index 986852a..d343059 100644 --- a/src/Controller/ProductPhotosController.php +++ b/src/Controller/ProductPhotosController.php @@ -32,6 +32,7 @@ class ProductPhotosController extends AppController { * * @param string|null $id Product Photo id. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * * @return \Cake\Http\Response|null|void Renders view */ public function view($id = null) { @@ -51,7 +52,7 @@ class ProductPhotosController extends AppController { if (!$this->request->getData('photo')) { $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.'); $productCategory = $productPhoto->product_category_id ? $this->fetchTable('CakeProducts.ProductCategories')->find() - ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; + ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; $productCatalogs = $this->fetchTable('CakeProducts.ProductCatalogs')->find('list')->toArray(); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); @@ -70,6 +71,9 @@ class ProductPhotosController extends AppController { 'ProductSkus.id' => $this->request->getData('product_sku_id'), ]) ->first(); + /** + * @var \CakeProducts\Model\Entity\ProductSku|null $productSku + */ $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; $postData['product_id'] = $productSku->product->id ?? null; @@ -82,6 +86,9 @@ class ProductPhotosController extends AppController { 'Products.id' => $this->request->getData('product_id'), ]) ->first(); + /** + * @var \CakeProducts\Model\Entity\Product|null $product + */ $path = $product ? $product->id : $path; $postData['product_category_id'] = $product->product_category->internal_id ?? null; @@ -90,7 +97,7 @@ class ProductPhotosController extends AppController { // @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id'; - $productCategoryPosted = $this->fetchTable('ProductCategories') + $productCategoryPosted = $this->fetchTable('CakeProducts.ProductCategories') ->find() ->where([ $field => $categoryId, @@ -138,7 +145,7 @@ class ProductPhotosController extends AppController { $this->Flash->error(__('The product photo could not be saved. Please, try again.')); } $productCategory = $productPhoto->product_category_id ? $this->fetchTable('ProductCategories')->find() - ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; + ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray(); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); } @@ -148,7 +155,8 @@ class ProductPhotosController extends AppController { * * @param string|null $id Product Photo id. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. - * @return Response|null|void Redirects on successful edit, renders view otherwise. + * + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ public function edit($id = null) { $productPhoto = $this->fetchTable()->get($id, contain: []); @@ -173,7 +181,7 @@ class ProductPhotosController extends AppController { * * @param string|null $id Product Photo id. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. - * @return Response|null Redirects to index. + * @return \Cake\Http\Response|null Redirects to index. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); diff --git a/src/Controller/ProductVariantsController.php b/src/Controller/ProductVariantsController.php index 7163b64..9a17182 100644 --- a/src/Controller/ProductVariantsController.php +++ b/src/Controller/ProductVariantsController.php @@ -48,7 +48,7 @@ class ProductVariantsController extends AppController { if ($this->request->is('post')) { $saveOptions = []; $postData = $this->request->getData(); - /** + /** * @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant */ $productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1')); diff --git a/src/Controller/ProductsController.php b/src/Controller/ProductsController.php index 006f14b..e47f591 100644 --- a/src/Controller/ProductsController.php +++ b/src/Controller/ProductsController.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace CakeProducts\Controller; use Cake\Log\Log; -use CakeProducts\Model\Entity\ProductCategoryVariant; /** * Products Controller @@ -77,7 +76,11 @@ class ProductsController extends AppController { if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { continue; } - $existingVariant = $this->fetchTable('ProductCategoryVariants')->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); + /** + * @var \CakeProducts\Model\Entity\ProductCategoryVariant $existingVariant + */ + $existingVariant = $this->fetchTable('CakeProducts.ProductCategoryVariants') + ->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); $optionsData = []; foreach ($existingVariant->product_category_variant_options as $existingOption) { $optionsData[] = [ @@ -124,7 +127,7 @@ class ProductsController extends AppController { $this->Flash->error(__('The product could not be saved. Please, try again.')); } $productCategory = $product->product_category_id ? $this->fetchTable('ProductCategories')->find() - ->where(['internal_id' => $product->product_category_id])->first() : null; + ->where(['internal_id' => $product->product_category_id])->first() : null; $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray(); $this->set(compact('product', 'productCatalogs', 'productCategory')); diff --git a/src/Model/Entity/ProductCategoryVariant.php b/src/Model/Entity/ProductCategoryVariant.php index 8127643..658b1e3 100644 --- a/src/Model/Entity/ProductCategoryVariant.php +++ b/src/Model/Entity/ProductCategoryVariant.php @@ -15,8 +15,8 @@ use Cake\ORM\Entity; * @property bool $enabled * @property bool $is_system_variant * - * @property ProductCategory|\Cake\Datasource\EntityInterface $product_category - * @property ProductCategoryVariantOption[]|\Cake\Datasource\EntityInterface[] $product_category_variant_options + * @property ProductCategory $product_category + * @property ProductCategoryVariantOption[] $product_category_variant_options */ class ProductCategoryVariant extends Entity { diff --git a/src/Model/Table/ProductCategoriesTable.php b/src/Model/Table/ProductCategoriesTable.php index 199daab..ae40e97 100644 --- a/src/Model/Table/ProductCategoriesTable.php +++ b/src/Model/Table/ProductCategoriesTable.php @@ -63,7 +63,7 @@ class ProductCategoriesTable extends Table { ]); $this->belongsTo('ProductCatalogs', [ - 'className' => 'CakeProducts.ProductCatalogs', + 'className' => 'CakeProducts.ProductCatalogs', 'foreignKey' => 'product_catalog_id', 'joinType' => 'INNER', ]); @@ -78,35 +78,35 @@ class ProductCategoriesTable extends Table { 'cascadeCallbacks' => true, ]); $this->hasMany('ProductCategoryAttributes', [ - 'className' => 'CakeProducts.ProductCategoryAttributes', + 'className' => 'CakeProducts.ProductCategoryAttributes', 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'dependent' => true, 'cascadeCallbacks' => true, ]); $this->hasMany('ProductCategoryVariants', [ - 'className' => 'CakeProducts.ProductCategoryVariants', + 'className' => 'CakeProducts.ProductCategoryVariants', 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'dependent' => true, 'cascadeCallbacks' => true, ]); $this->hasMany('Products', [ - 'className' => 'CakeProducts.Products', + 'className' => 'CakeProducts.Products', 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'dependent' => true, 'cascadeCallbacks' => true, ]); $this->hasMany('ProductPhotos', [ - 'className' => 'CakeProducts.ProductPhotos', + 'className' => 'CakeProducts.ProductPhotos', 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'dependent' => true, 'cascadeCallbacks' => true, ]); $this->hasOne('PrimaryProductPhotos', [ - 'className' => 'CakeProducts.ProductPhotos', + 'className' => 'CakeProducts.ProductPhotos', 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], diff --git a/src/Model/Table/ProductPhotosTable.php b/src/Model/Table/ProductPhotosTable.php index 01d9ddc..d2974f0 100644 --- a/src/Model/Table/ProductPhotosTable.php +++ b/src/Model/Table/ProductPhotosTable.php @@ -27,7 +27,7 @@ use Cake\Validation\Validator; * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> deleteManyOrFail(iterable $entities, array $options = []) - * + * * @mixin \Cake\ORM\Behavior\TimestampBehavior */ class ProductPhotosTable extends Table {