autowp/autowp

View on GitHub
module/Application/src/Model/Picture.php

Summary

Maintainability
F
1 wk
Test Coverage
F
58%

File Picture.php has 1006 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Application\Model;

use Application\Comments;
Severity: Major
Found in module/Application/src/Model/Picture.php - About 2 days to fix

    Function getSelect has a Cognitive Complexity of 95 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getSelect(array $options): Sql\Select
        {
            $defaults = [
                'id'               => null,
                'id_exclude'       => null,
    Severity: Minor
    Found in module/Application/src/Model/Picture.php - About 1 day 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 getSelect has 350 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getSelect(array $options): Sql\Select
        {
            $defaults = [
                'id'               => null,
                'id_exclude'       => null,
    Severity: Major
    Found in module/Application/src/Model/Picture.php - About 1 day to fix

      Method getFileNamePattern has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getFileNamePattern(int $pictureId): string
          {
              $result = rand(1, 9999);
      
              $filenameFilter = new FilenameSafe();
      Severity: Major
      Found in module/Application/src/Model/Picture.php - About 4 hrs to fix

        Method getNameData has 103 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getNameData($rows, array $options = []): array
            {
                $result = [];
        
                $language = $options['language'] ?? 'en';
        Severity: Major
        Found in module/Application/src/Model/Picture.php - About 4 hrs to fix

          Function getFileNamePattern has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getFileNamePattern(int $pictureId): string
              {
                  $result = rand(1, 9999);
          
                  $filenameFilter = new FilenameSafe();
          Severity: Minor
          Found in module/Application/src/Model/Picture.php - About 4 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

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

          class Picture
          {
              public const
                  STATUS_ACCEPTED = 'accepted',
                  STATUS_REMOVING = 'removing',

          Function getNameData has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getNameData($rows, array $options = []): array
              {
                  $result = [];
          
                  $language = $options['language'] ?? 'en';
          Severity: Minor
          Found in module/Application/src/Model/Picture.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 applyItemFilters has 80 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function applyItemFilters(Sql\Select $select, $options, bool $forceJoinItem): array
              {
                  if (! is_array($options)) {
                      $options = [
                          'id' => $options,
          Severity: Major
          Found in module/Application/src/Model/Picture.php - About 3 hrs to fix

            Picture has 25 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class Picture
            {
                public const
                    STATUS_ACCEPTED = 'accepted',
                    STATUS_REMOVING = 'removing',
            Severity: Minor
            Found in module/Application/src/Model/Picture.php - About 2 hrs to fix

              Function applyItemFilters has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function applyItemFilters(Sql\Select $select, $options, bool $forceJoinItem): array
                  {
                      if (! is_array($options)) {
                          $options = [
                              'id' => $options,
              Severity: Minor
              Found in module/Application/src/Model/Picture.php - About 2 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 applyColumns has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function applyColumns(Sql\Select $select, array $columns): void
                  {
                      $result = [];
              
                      foreach ($columns as $key => $column) {
              Severity: Minor
              Found in module/Application/src/Model/Picture.php - About 1 hr to fix

                Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        TableGateway $table,
                        TableGateway $itemTable,
                        PictureModerVote $pictureModerVote,
                        TableGateway $pictureItemTable,
                        Perspective $perspective
                Severity: Minor
                Found in module/Application/src/Model/Picture.php - About 35 mins to fix

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

                      private function applyColumns(Sql\Select $select, array $columns): void
                      {
                          $result = [];
                  
                          foreach ($columns as $key => $column) {
                  Severity: Minor
                  Found in module/Application/src/Model/Picture.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

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

                      private function applyAncestorFilter(Sql\Select $select, $options, string $idColumn): void
                      {
                          if (! is_array($options)) {
                              $options = ['id' => $options];
                          }
                  Severity: Minor
                  Found in module/Application/src/Model/Picture.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

                  Function applyIdFilter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function applyIdFilter(Sql\Select $select, $value, string $id): void
                      {
                          if (is_array($value)) {
                              $value = array_values($value);
                  
                  
                  Severity: Minor
                  Found in module/Application/src/Model/Picture.php - About 25 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 getNameData() has 126 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function getNameData($rows, array $options = []): array
                      {
                          $result = [];
                  
                          $language = $options['language'] ?? 'en';

                  The method getFileNamePattern() has 131 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function getFileNamePattern(int $pictureId): string
                      {
                          $result = rand(1, 9999);
                  
                          $filenameFilter = new FilenameSafe();

                  The class Picture has 1230 lines of code. Current threshold is 1000. Avoid really long classes.
                  Open

                  class Picture
                  {
                      public const
                          STATUS_ACCEPTED = 'accepted',
                          STATUS_REMOVING = 'removing',

                  The method getSelect() has 405 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function getSelect(array $options): Sql\Select
                      {
                          $defaults = [
                              'id'               => null,
                              'id_exclude'       => null,

                  The method getSelect() has an NPath complexity of 34828517376000. The configured NPath complexity threshold is 200.
                  Open

                      public function getSelect(array $options): Sql\Select
                      {
                          $defaults = [
                              'id'               => null,
                              'id_exclude'       => null,

                  NPathComplexity

                  Since: 0.1

                  The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                  Example

                  class Foo {
                      function bar() {
                          // lots of complicated code
                      }
                  }

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

                  The method getNameData() has an NPath complexity of 924. The configured NPath complexity threshold is 200.
                  Open

                      public function getNameData($rows, array $options = []): array
                      {
                          $result = [];
                  
                          $language = $options['language'] ?? 'en';

                  NPathComplexity

                  Since: 0.1

                  The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                  Example

                  class Foo {
                      function bar() {
                          // lots of complicated code
                      }
                  }

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

                  The method applyItemFilters() has 103 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      private function applyItemFilters(Sql\Select $select, $options, bool $forceJoinItem): array
                      {
                          if (! is_array($options)) {
                              $options = [
                                  'id' => $options,

                  The method applyItemFilters() has an NPath complexity of 98304. The configured NPath complexity threshold is 200.
                  Open

                      private function applyItemFilters(Sql\Select $select, $options, bool $forceJoinItem): array
                      {
                          if (! is_array($options)) {
                              $options = [
                                  'id' => $options,

                  NPathComplexity

                  Since: 0.1

                  The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                  Example

                  class Foo {
                      function bar() {
                          // lots of complicated code
                      }
                  }

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

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

                      public function getSelect(array $options): Sql\Select
                      {
                          $defaults = [
                              'id'               => null,
                              'id_exclude'       => null,

                  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 applyItemFilters() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
                  Open

                      private function applyItemFilters(Sql\Select $select, $options, bool $forceJoinItem): array
                      {
                          if (! is_array($options)) {
                              $options = [
                                  'id' => $options,

                  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 getNameData() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function getNameData($rows, array $options = []): array
                      {
                          $result = [];
                  
                          $language = $options['language'] ?? 'en';

                  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 getFileNamePattern() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function getFileNamePattern(int $pictureId): string
                      {
                          $result = rand(1, 9999);
                  
                          $filenameFilter = new FilenameSafe();

                  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 applyColumns() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
                  Open

                      private function applyColumns(Sql\Select $select, array $columns): void
                      {
                          $result = [];
                  
                          foreach ($columns as $key => $column) {

                  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 class Picture has a coupling between objects value of 28. Consider to reduce the number of dependencies under 13.
                  Open

                  class Picture
                  {
                      public const
                          STATUS_ACCEPTED = 'accepted',
                          STATUS_REMOVING = 'removing',

                  CouplingBetweenObjects

                  Since: 1.1.0

                  A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                  Example

                  class Foo {
                      /**
                       * @var \foo\bar\X
                       */
                      private $x = null;
                  
                      /**
                       * @var \foo\bar\Y
                       */
                      private $y = null;
                  
                      /**
                       * @var \foo\bar\Z
                       */
                      private $z = null;
                  
                      public function setFoo(\Foo $foo) {}
                      public function setBar(\Bar $bar) {}
                      public function setBaz(\Baz $baz) {}
                  
                      /**
                       * @return \SplObjectStorage
                       * @throws \OutOfRangeException
                       * @throws \InvalidArgumentException
                       * @throws \ErrorException
                       */
                      public function process(\Iterator $it) {}
                  
                      // ...
                  }

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

                  The method getFileNamePattern uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                  } else {
                                      $carFolder = $filenameFilter->filter($car['name']);
                                      $firstChar = mb_substr($carFolder, 0, 1);
                                      $result    = $firstChar . '/' . $carFolder . '/' . $carCatname;
                                  }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method applyColumns uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                      } else {
                                          $result[$key] = $column;
                                      }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  Avoid using static access to class '\DateTime' in method 'getSelect'.
                  Open

                              $date = DateTime::createFromFormat('Y-m-d', $options['added_from'], $timezone);

                  StaticAccess

                  Since: 1.4.0

                  Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

                  Example

                  class Foo
                  {
                      public function bar()
                      {
                          Bar::baz();
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#staticaccess

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $select
                                      ->join(['pdr' => 'pictures_moder_votes'], 'pictures.id = pdr.picture_id', [], $select::JOIN_LEFT)
                                      ->where('pdr.picture_id IS NULL');
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $select->where(['pictures.point IS NULL']);
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $joinLeftComments = true;
                                  $select->where(['(comment_topic.messages = 0 or comment_topic.messages is null)']);
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  Avoid using static access to class '\DateTime' in method 'setDateFilter'.
                  Open

                          $dateObj = DateTime::createFromFormat('Y-m-d', $date, $timezone);

                  StaticAccess

                  Since: 1.4.0

                  Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

                  Example

                  class Foo
                  {
                      public function bar()
                      {
                          Bar::baz();
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#staticaccess

                  The method applyItemFilters uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $select->where([new Sql\Predicate\IsNotNull('picture_item.perspective_id')]);
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $select->where(['pictures.status' => $value]);
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method getFileNamePattern uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  if (count($sBrands) === 1) {
                                      $sBrandsA = array_values($sBrands);
                                      $brand    = $sBrandsA[0];
                  
                  

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  Avoid using static access to class '\rand' in method 'randomIdentity'.
                  Open

                          return Rand::getString(1, $alpha) . Rand::getString(self::IDENTITY_LENGTH - 1, $alpha . $number);

                  StaticAccess

                  Since: 1.4.0

                  Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

                  Example

                  class Foo
                  {
                      public function bar()
                      {
                          Bar::baz();
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#staticaccess

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                      } else {
                                          $select->where(['similar.status' => $value]);
                                      }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $select->where(['pictures.replace_picture_id is null']);
                              }

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  Avoid using static access to class '\rand' in method 'randomIdentity'.
                  Open

                          return Rand::getString(1, $alpha) . Rand::getString(self::IDENTITY_LENGTH - 1, $alpha . $number);

                  StaticAccess

                  Since: 1.4.0

                  Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

                  Example

                  class Foo
                  {
                      public function bar()
                      {
                          Bar::baz();
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#staticaccess

                  The method getSelect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              switch ($options['order']) {
                                  case 'accept_datetime_desc':
                                      $select->order(['accept_datetime desc', 'pictures.add_date DESC', 'pictures.id DESC']);
                                      break;

                  ElseExpression

                  Since: 1.4.0

                  An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                  Example

                  class Foo
                  {
                      public function bar($flag)
                      {
                          if ($flag) {
                              // one branch
                          } else {
                              // another branch
                          }
                      }
                  }

                  Source https://phpmd.org/rules/cleancode.html#elseexpression

                  syntax error, unexpected 'TableGateway' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
                  Open

                      private TableGateway $table;
                  Severity: Critical
                  Found in module/Application/src/Model/Picture.php by phan

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

                      private function applyIdFilter(Sql\Select $select, $value, string $id): void
                      {
                          if (is_array($value)) {
                              $value = array_values($value);
                  
                  
                  Severity: Major
                  Found in module/Application/src/Model/Picture.php and 2 other locations - About 4 hrs to fix
                  module/Application/src/Model/Item.php on lines 1006..1030
                  module/User/src/Model/User.php on lines 109..133

                  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 176.

                  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 3 locations. Consider refactoring.
                  Open

                          $defaults = [
                              'id'                       => null,
                              'item_type_id'             => null,
                              'ancestor_or_self'         => null,
                              'exclude_ancestor_or_self' => null,
                  Severity: Major
                  Found in module/Application/src/Model/Picture.php and 2 other locations - About 1 hr to fix
                  module/Application/src/Model/Item.php on lines 1037..1050
                  module/User/src/Model/User.php on lines 143..156

                  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 104.

                  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 3 locations. Consider refactoring.
                  Open

                      public function isExists(array $options): bool
                      {
                          $select = $this->getSelect($options);
                          $select->reset($select::COLUMNS);
                          $select->reset($select::ORDER);
                  Severity: Major
                  Found in module/Application/src/Model/Picture.php and 2 other locations - About 45 mins to fix
                  module/Application/src/Model/Item.php on lines 1580..1590
                  module/User/src/Model/User.php on lines 268..278

                  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 96.

                  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

                  There are no issues that match your filters.

                  Category
                  Status