atrocore / atropim

AtroPIM is a modern, flexible, configurable, open-source product information management system (PIM) of a new generation.
https://atropim.com
GNU General Public License v3.0
149 stars 29 forks source link

Convert ten variable assignments to the usage of combined operators #193

Closed elfring closed 1 year ago

elfring commented 2 years ago

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of combined operators accordingly.

diff --git a/app/Repositories/AbstractRepository.php b/app/Repositories/AbstractRepository.php
index 7ab3f9f..c8cebbe 100644
--- a/app/Repositories/AbstractRepository.php
+++ b/app/Repositories/AbstractRepository.php
@@ -163,7 +163,7 @@ abstract class AbstractRepository extends Base
             $result[$k]['channel'] = '-';

             if (!empty($result[$k]['channelId'])) {
-                $result[$k]['id'] = $result[$k]['id'] . '_' . (string)$result[$k]['channelId'];
+                $result[$k]['id'] .= '_' . (string)$result[$k]['channelId'];
             }
         }

diff --git a/app/Repositories/Attribute.php b/app/Repositories/Attribute.php
index 0dca4c5..7001186 100644
--- a/app/Repositories/Attribute.php
+++ b/app/Repositories/Attribute.php
@@ -480,7 +480,7 @@ class Attribute extends AbstractRepository
             $sql = '';
             foreach ($data as $row) {
                 // increase max
-                $max = $max + 10;
+                $max += 10;

                 // prepare id
                 $id = $row['id'];
diff --git a/app/Repositories/Category.php b/app/Repositories/Category.php
index 8844640..c145795 100644
--- a/app/Repositories/Category.php
+++ b/app/Repositories/Category.php
@@ -437,7 +437,7 @@ class Category extends AbstractRepository
                 ->toArray();

             // increase sort order
-            $sortOrder = $sortOrder + 10;
+            $sortOrder += 10;

         } elseif ($entity->get('_position') == 'inside') {
             // get collection
@@ -465,7 +465,7 @@ class Category extends AbstractRepository
             $sql .= "UPDATE category SET sort_order=$sortOrder WHERE id='$id';";

             // increase sort order
-            $sortOrder = $sortOrder + 10;
+            $sortOrder += 10;
         }

         // execute sql
diff --git a/app/Repositories/Product.php b/app/Repositories/Product.php
index cbe2cd2..9f4960c 100644
--- a/app/Repositories/Product.php
+++ b/app/Repositories/Product.php
@@ -428,7 +428,7 @@ class Product extends AbstractRepository
                 $sql = '';
                 foreach ($ids as $id) {
                     // increase max
-                    $max = $max + 10;
+                    $max += 10;

                     // prepare sql
                     $sql .= "UPDATE product_category SET sorting='$max' WHERE id='$id';";
diff --git a/app/Services/Product.php b/app/Services/Product.php
index d0547f3..e3de537 100644
--- a/app/Services/Product.php
+++ b/app/Services/Product.php
@@ -536,7 +536,7 @@ class Product extends AbstractService
         $link = 'productAttributeValues';

         if (!empty($params['maxSize'])) {
-            $params['maxSize'] = $params['maxSize'] + 1;
+            $params['maxSize'] += 1;
         }

         // get select params
@@ -614,7 +614,7 @@ class Product extends AbstractService
                         $camelCaseLocale = ucfirst(Util::toCamelCase(strtolower($locale)));

                         $localePav = clone $pav;
-                        $localePav->id = $localePav->id . ProductAttributeValue::LOCALE_IN_ID_SEPARATOR . $locale;
+                        $localePav->id .= ProductAttributeValue::LOCALE_IN_ID_SEPARATOR . $locale;
                         $localePav->set('isLocale', true);
                         $localePav->set('locale', $locale);
                         $localePav->set('attributeName', $localePav->get('attributeName') . ' › ' . $locale);
diff --git a/app/Services/ProductTypesDashlet.php b/app/Services/ProductTypesDashlet.php
index 9810911..6659695 100644
--- a/app/Services/ProductTypesDashlet.php
+++ b/app/Services/ProductTypesDashlet.php
@@ -70,8 +70,8 @@ class ProductTypesDashlet extends AbstractProductDashletService

         // prepare result
         foreach ($productData as $type => $value) {
-            $value['active'] = $value['active'] ?? 0;
-            $value['notActive'] = $value['notActive'] ?? 0;
+            $value['active'] ??= 0;
+            $value['notActive'] ??= 0;

             $result['list'][] = [
                 'id'        => $type,
diff --git a/app/Services/RevisionField.php b/app/Services/RevisionField.php
index 110d5d2..52cdcfc 100644
--- a/app/Services/RevisionField.php
+++ b/app/Services/RevisionField.php
@@ -138,7 +138,7 @@ class RevisionField extends MultilangRevisionField
                                 "field"    => $fieldName
                             ];

-                            $result['total'] = $result['total'] + 1;
+                            $result['total'] += 1;
                         }
                     }
                 }
elfring commented 1 year ago

:thought_balloon: I would appreciate more constructive feedback.

atrolex commented 1 year ago

What you offer is a matter of taste and code readibility (not reducing number of characters), it improves nothing. In the future, you can create pull requests directly, to start our standard review process. But I can say to you already, changes like above will not be accepted :)

elfring commented 1 year ago

:thought_balloon: The usage of combined operators can eventually influence the software run time characteristics in desirable directions, can't it?

atrolex commented 1 year ago

It can, but in this case not in a way to be worth it, to make this change.

elfring commented 1 year ago

:thinking: I got the impression that combined (or compound/augmented) operators can become more helpful at several source code places.