lovata/oc-toolbox-plugin

View on GitHub
classes/helper/AbstractImportModel.php

Summary

Maintainability
C
7 hrs
Test Coverage

The class AbstractImportModel has an overall complexity of 66 which is very high. The configured complexity threshold is 50.
Open

abstract class AbstractImportModel
{
    use TraitInitActiveLang;

    const EVENT_BEFORE_IMPORT = 'model.beforeImport';

Function importImageList has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    protected function importImageList()
    {
        if (!$this->bNeedUpdateImageList) {
            return;
        }
Severity: Minor
Found in classes/helper/AbstractImportModel.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method importImageList has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function importImageList()
    {
        if (!$this->bNeedUpdateImageList) {
            return;
        }
Severity: Minor
Found in classes/helper/AbstractImportModel.php - About 1 hr to fix

    Method importPreviewImage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function importPreviewImage()
        {
            if (!$this->bNeedUpdatePreviewImage) {
                return;
            }
    Severity: Minor
    Found in classes/helper/AbstractImportModel.php - About 1 hr to fix

      Function importPreviewImage has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function importPreviewImage()
          {
              if (!$this->bNeedUpdatePreviewImage) {
                  return;
              }
      Severity: Minor
      Found in classes/helper/AbstractImportModel.php - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function processModelObject has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function processModelObject()
          {
              $arActiveLangList = $this->getActiveLangList();
              if (empty($arActiveLangList) || empty($this->obModel)) {
                  return;
      Severity: Minor
      Found in classes/helper/AbstractImportModel.php - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function fireBeforeImportEvent has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function fireBeforeImportEvent()
          {
              $arEventData = [static::MODEL_CLASS, $this->arImportData];
      
              $arEventData = Event::fire(self::EVENT_BEFORE_IMPORT, $arEventData);
      Severity: Minor
      Found in classes/helper/AbstractImportModel.php - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      The method importPreviewImage() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
      Open

          protected function importPreviewImage()
          {
              if (!$this->bNeedUpdatePreviewImage) {
                  return;
              }

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

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

      The method importImageList() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
      Open

          protected function importImageList()
          {
              if (!$this->bNeedUpdateImageList) {
                  return;
              }

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

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

      Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
      Open

          protected function importImageList()

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Avoid using empty try-catch blocks in importImageList.
      Open

                          } catch (\Exception $obException) {}

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

      Source https://phpmd.org/rules/design.html#emptycatchblock

      Avoid using empty try-catch blocks in importImageList.
      Open

                          } catch (\Exception $obException) {}

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

      Source https://phpmd.org/rules/design.html#emptycatchblock

      Avoid using empty try-catch blocks in importPreviewImage.
      Open

                  } catch (\Exception $obException) {}

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

      Source https://phpmd.org/rules/design.html#emptycatchblock

      Avoid using empty try-catch blocks in removeAllImages.
      Open

                  } catch (\Exception $obException) {}

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

      Source https://phpmd.org/rules/design.html#emptycatchblock

      Either remove or fill this block of code.
      Open

                  } catch (\Exception $obException) {}

      Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

      Noncompliant Code Example

      for ($i = 0; $i < 42; $i++){}  // Empty on purpose or missing piece of code ?
      

      Exceptions

      When a block contains a comment, this block is not considered to be empty.

      Either remove or fill this block of code.
      Open

                          } catch (\Exception $obException) {}

      Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

      Noncompliant Code Example

      for ($i = 0; $i < 42; $i++){}  // Empty on purpose or missing piece of code ?
      

      Exceptions

      When a block contains a comment, this block is not considered to be empty.

      Either remove or fill this block of code.
      Open

                          } catch (\Exception $obException) {}

      Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

      Noncompliant Code Example

      for ($i = 0; $i < 42; $i++){}  // Empty on purpose or missing piece of code ?
      

      Exceptions

      When a block contains a comment, this block is not considered to be empty.

      Either remove or fill this block of code.
      Open

                  } catch (\Exception $obException) {}

      Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

      Noncompliant Code Example

      for ($i = 0; $i < 42; $i++){}  // Empty on purpose or missing piece of code ?
      

      Exceptions

      When a block contains a comment, this block is not considered to be empty.

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

              $bActive = array_get($this->arImportData, 'active');

      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.

      Closing brace must be on a line by itself
      Open

                          } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                          } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                  } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                  } catch (\Exception $obException) {}

      Newline required after opening brace
      Open

                          } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                          } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                          } catch (\Exception $obException) {}

      Newline required after opening brace
      Open

                  } catch (\Exception $obException) {}

      Newline required after opening brace
      Open

                          } catch (\Exception $obException) {}

      Newline required after opening brace
      Open

                  } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                  } catch (\Exception $obException) {}

      Closing brace must be on a line by itself
      Open

                  } catch (\Exception $obException) {}

      There are no issues that match your filters.

      Category
      Status