lovata/oc-shopaholic-plugin

View on GitHub
models/Offer.php

Summary

Maintainability
D
2 days
Test Coverage

File Offer.php has 333 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php namespace Lovata\Shopaholic\Models;

use Backend\Models\ImportModel;

use October\Rain\Database\Traits\Sortable;
Severity: Minor
Found in models/Offer.php - About 4 hrs to fix

    Offer has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Offer extends ImportModel
    {
        use Validation;
        use SoftDelete;
        use Purgeable;
    Severity: Minor
    Found in models/Offer.php - About 2 hrs to fix

      The class Offer has 25 fields. Consider redesigning Offer to keep the number of fields under 20.
      Open

      class Offer extends ImportModel
      {
          use Validation;
          use SoftDelete;
          use Purgeable;
      Severity: Minor
      Found in models/Offer.php by phpmd

      TooManyFields

      Since: 0.1

      Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

      Example

      class Person {
         protected $one;
         private $two;
         private $three;
         [... many more fields ...]
      }

      Source https://phpmd.org/rules/codesize.html#toomanyfields

      Class "Offer" has 21 methods, which is greater than 20 authorized. Split it into smaller classes.
      Open

      class Offer extends ImportModel
      Severity: Major
      Found in models/Offer.php by sonar-php

      A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

      Avoid unused parameters such as '$sSessionKey'.
      Open

          public function importData($arElementList, $sSessionKey = null)
      Severity: Minor
      Found in models/Offer.php by phpmd

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      Define a constant instead of duplicating this literal "description" 3 times.
      Open

          public $translatable = ['name', 'preview_text', 'description'];
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "price" 7 times.
      Wontfix

              'price',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "preview_text" 3 times.
      Open

          public $translatable = ['name', 'preview_text', 'description'];
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "price_list" 3 times.
      Open

              'price_list',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "quantity_in_unit" 3 times.
      Open

              'quantity_in_unit',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "quantity" 4 times.
      Wontfix

              'quantity',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "old_price" 7 times.
      Wontfix

              'old_price',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "measure_of_unit_id" 3 times.
      Open

              'measure_of_unit' => [Measure::class, 'key' => 'measure_of_unit_id', 'order' => 'name asc'],
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "product_id" 3 times.
      Open

              'product_id',
      Severity: Critical
      Found in models/Offer.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Identical blocks of code found in 4 locations. Consider refactoring.
      Open

          public function importData($arElementList, $sSessionKey = null)
          {
              if (empty($arElementList)) {
                  return;
              }
      Severity: Major
      Found in models/Offer.php and 3 other locations - About 4 hrs to fix
      models/Brand.php on lines 166..187
      models/Category.php on lines 210..231
      models/Product.php on lines 286..307

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 132.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if ($this->fSavedPrice !== null) {
                  $fPrice = $this->fSavedPrice;
              } else {
                  $obPriceModel = $this->getPriceObject($this->getActivePriceType());
                  $this->setActivePriceType(null);
      Severity: Major
      Found in models/Offer.php and 1 other location - About 1 hr to fix
      models/Offer.php on lines 429..440

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 73.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if ($this->fSavedOldPrice !== null) {
                  $fPrice = $this->fSavedOldPrice;
              } else {
                  $obPriceModel = $this->getPriceObject($this->getActivePriceType());
                  $this->setActivePriceType(null);
      Severity: Major
      Found in models/Offer.php and 1 other location - About 1 hr to fix
      models/Offer.php on lines 405..416

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 73.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          public $cached = [
              'id',
              'active',
              'product_id',
              'name',
      Severity: Major
      Found in models/Offer.php and 1 other location - About 1 hr to fix
      models/Offer.php on lines 194..213

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 61.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          public $fillable = [
              'active',
              'name',
              'code',
              'product_id',
      Severity: Major
      Found in models/Offer.php and 1 other location - About 1 hr to fix
      models/Offer.php on lines 215..234

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 61.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Avoid excessively long variable names like $bAllowNegativeOfferQuantity. Keep variable name length under 25.
      Open

              $bAllowNegativeOfferQuantity = (bool) Settings::getValue('allow_negative_offer_quantity');
      Severity: Minor
      Found in models/Offer.php by phpmd

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      Variable "price_type_id" is not in valid camel caps format
      Open

                  $arResult[$obPrice->price_type_id] = [
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "discount_price_value" is not in valid camel caps format
      Open

              $fPrice = $obPriceModel->discount_price_value;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "old_price_value" is not in valid camel caps format
      Open

                  $fPrice = $obPriceModel->old_price_value;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "price_link" is not in valid camel caps format
      Open

                  $obPriceModel = $this->price_link->where('price_type_id', $iPriceTypeID)->first();
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "price_value" is not in valid camel caps format
      Open

                  $fPrice = $obPriceModel->price_value;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "price_link" is not in valid camel caps format
      Open

              foreach ($this->price_link as $obPrice) {
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "main_price" is not in valid camel caps format
      Open

                  $obPriceModel = $this->main_price;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "old_price_value" is not in valid camel caps format
      Open

                      'old_price' => $obPrice->old_price_value,
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "old_price" is not in valid camel caps format
      Open

                  $obPriceModel->old_price = $fOldPrice !== null ? $fOldPrice : $obPriceModel->old_price;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "old_price" is not in valid camel caps format
      Open

                  $obPriceModel->old_price = $fOldPrice !== null ? $fOldPrice : $obPriceModel->old_price;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "main_price" is not in valid camel caps format
      Open

                      $this->main_price = $obPriceModel;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "price_value" is not in valid camel caps format
      Open

                      'price'     => $obPrice->price_value,
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      Variable "tax_percent" is not in valid camel caps format
      Open

              return $obOfferItem->tax_percent;
      Severity: Minor
      Found in models/Offer.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status