autowp/image

View on GitHub
src/Sampler.php

Summary

Maintainability
F
6 days
Test Coverage
B
84%

File Sampler.php has 558 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Autowp\Image;
Severity: Major
Found in src/Sampler.php - About 1 day to fix

    Function convertImagick has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
        {
            if (! $format instanceof Sampler\Format) {
                if (! is_array($format)) {
                    throw new Sampler\Exception("Unexpected type of format");
    Severity: Minor
    Found in src/Sampler.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

    Method convertImagick has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
        {
            if (! $format instanceof Sampler\Format) {
                if (! is_array($format)) {
                    throw new Sampler\Exception("Unexpected type of format");
    Severity: Major
    Found in src/Sampler.php - About 3 hrs to fix

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

      class Sampler
      {
          /**
           * @throws ImagickException
           */
      Severity: Minor
      Found in src/Sampler.php by phpmd

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

          private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
          {
              $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
              if (! $cropSet) {
                  throw new Sampler\Exception('Crop parameters not properly set');
      Severity: Minor
      Found in src/Sampler.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 cropImage has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
          {
              $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
              if (! $cropSet) {
                  throw new Sampler\Exception('Crop parameters not properly set');
      Severity: Major
      Found in src/Sampler.php - About 2 hrs to fix

        Method extendHorizontal has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function extendHorizontal(Imagick $imagick, Sampler\Format $format): void
            {
                $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
        
                $srcWidth  = $imagick->getImageWidth();
        Severity: Minor
        Found in src/Sampler.php - About 2 hrs to fix

          Method extendVertical has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function extendVertical(Imagick $imagick, Sampler\Format $format): void
              {
                  $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
          
                  $srcWidth  = $imagick->getImageWidth();
          Severity: Minor
          Found in src/Sampler.php - About 2 hrs to fix

            Method convertByOuterFit has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function convertByOuterFit(Imagick $imagick, Sampler\Format $format): Imagick
                {
                    $srcWidth  = $imagick->getImageWidth();
                    $srcHeight = $imagick->getImageHeight();
                    $srcRatio  = $srcWidth / $srcHeight;
            Severity: Minor
            Found in src/Sampler.php - About 1 hr to fix

              Function convertByInnerFit has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function convertByInnerFit(Imagick $imagick, Sampler\Format $format): Imagick
                  {
                      $srcWidth  = $imagick->getImageWidth();
                      $srcHeight = $imagick->getImageHeight();
                      $srcRatio  = $srcWidth / $srcHeight;
              Severity: Minor
              Found in src/Sampler.php - About 1 hr 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 convertByInnerFit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function convertByInnerFit(Imagick $imagick, Sampler\Format $format): Imagick
                  {
                      $srcWidth  = $imagick->getImageWidth();
                      $srcHeight = $imagick->getImageHeight();
                      $srcRatio  = $srcWidth / $srcHeight;
              Severity: Minor
              Found in src/Sampler.php - About 1 hr to fix

                Function convertByMaximumFit has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function convertByMaximumFit(Imagick $imagick, Sampler\Format $format): Imagick
                    {
                        $srcWidth  = $imagick->getImageWidth();
                        $srcHeight = $imagick->getImageHeight();
                        $srcRatio  = $srcWidth / $srcHeight;
                Severity: Minor
                Found in src/Sampler.php - About 1 hr 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 extendVertical has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function extendVertical(Imagick $imagick, Sampler\Format $format): void
                    {
                        $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
                
                        $srcWidth  = $imagick->getImageWidth();
                Severity: Minor
                Found in src/Sampler.php - About 1 hr 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 convertByOuterFit has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function convertByOuterFit(Imagick $imagick, Sampler\Format $format): Imagick
                    {
                        $srcWidth  = $imagick->getImageWidth();
                        $srcHeight = $imagick->getImageHeight();
                        $srcRatio  = $srcWidth / $srcHeight;
                Severity: Minor
                Found in src/Sampler.php - About 1 hr 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 extendHorizontal has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function extendHorizontal(Imagick $imagick, Sampler\Format $format): void
                    {
                        $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
                
                        $srcWidth  = $imagick->getImageWidth();
                Severity: Minor
                Found in src/Sampler.php - About 1 hr 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 convertByMaximumFit has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function convertByMaximumFit(Imagick $imagick, Sampler\Format $format): Imagick
                    {
                        $srcWidth  = $imagick->getImageWidth();
                        $srcHeight = $imagick->getImageHeight();
                        $srcRatio  = $srcWidth / $srcHeight;
                Severity: Minor
                Found in src/Sampler.php - About 1 hr to fix

                  Method extendEdgeColor has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function extendEdgeColor(ImagickPixelIterator $iterator): ?ImagickPixel
                      {
                          $sum = [
                              'r' => [],
                              'g' => [],
                  Severity: Minor
                  Found in src/Sampler.php - About 1 hr to fix

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

                        private function crop(Imagick $imagick, int $width, int $height, int $left, int $top): Imagick
                    Severity: Minor
                    Found in src/Sampler.php - About 35 mins to fix

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

                          public function convertToFile($source, string $destFile, $format): void
                          {
                              if ($source instanceof Imagick) {
                                  $imagick = clone $source; // to prevent modifying source
                              } else {
                      Severity: Minor
                      Found in src/Sampler.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 convertImagick() has an NPath complexity of 110592. The configured NPath complexity threshold is 200.
                      Open

                          public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
                          {
                              if (! $format instanceof Sampler\Format) {
                                  if (! is_array($format)) {
                                      throw new Sampler\Exception("Unexpected type of format");
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertImagick() has 107 lines of code. Current threshold is set to 100. Avoid really long methods.
                      Open

                          public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
                          {
                              if (! $format instanceof Sampler\Format) {
                                  if (! is_array($format)) {
                                      throw new Sampler\Exception("Unexpected type of format");
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      The method cropImage() has an NPath complexity of 1056. The configured NPath complexity threshold is 200.
                      Open

                          private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
                          {
                              $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
                              if (! $cropSet) {
                                  throw new Sampler\Exception('Crop parameters not properly set');
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

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

                          public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
                          {
                              if (! $format instanceof Sampler\Format) {
                                  if (! is_array($format)) {
                                      throw new Sampler\Exception("Unexpected type of format");
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

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

                          private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
                          {
                              $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
                              if (! $cropSet) {
                                  throw new Sampler\Exception('Crop parameters not properly set');
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 standardDeviation has a boolean flag argument $sample, which is a certain sign of a Single Responsibility Principle violation.
                      Open

                          private function standardDeviation(array $values, bool $sample = false): float
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      BooleanArgumentFlag

                      Since: 1.4.0

                      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

                      Example

                      class Foo {
                          public function bar($flag = true) {
                          }
                      }

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

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

                              } else {
                                  if ($fWidth) {
                                      $decomposited = $this->convertByWidth($decomposited, $format);
                                  } elseif ($fHeight) {
                                      $decomposited = $this->convertByHeight($decomposited, $format);
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                                  } else {
                                      // добавляем поля по бокам
                                      $scaleWidth  = (int) round($formatHeight * $srcRatio);
                                      $scaleHeight = $formatHeight;
                                  }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $decomposited = $imagick;
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 scaleImage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $imagick->scaleImage($width, $height, false);
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertToFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $imagick = new Imagick();
                                  if (! $imagick->readImage($source)) {
                                      throw new Sampler\Exception("Error read image from `$source`");
                                  }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 crop uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $imagick->setImagePage(0, 0, 0, 0);
                                  $imagick->cropImage($width, $height, $left, $top);
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  // высчитываем размеры обрезания
                                  if ($ratio < $srcRatio) {
                                      $scaleWidth  = $formatWidth;
                                      $scaleHeight = (int) round($formatWidth / $srcRatio);
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByInnerFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                                  } else {
                                      // высокая картинка
                                      $cropWidth  = $srcWidth;
                                      $cropHeight = (int) round($srcWidth / $ratio);
                                      $cropLeft   = 0;
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                                      } else {
                                          $this->extendHorizontal($decomposited, $format);
                                      }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByOuterFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  if ($ratio < $srcRatio) {
                                      $scaleWidth = $formatWidth;
                                      // add top and bottom margins
                                      $scaleHeight = (int) round($formatWidth / $srcRatio);
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $imagick = $decomposited;
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByInnerFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  // высчитываем размеры обрезания
                                  if ($ratio < $srcRatio) {
                                      // широкая картинка
                                      $cropWidth  = (int) round($srcHeight * $ratio);
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByOuterFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                                  } else {
                                      // add left and right margins
                                      $scaleWidth  = (int) round($formatHeight * $srcRatio);
                                      $scaleHeight = $formatHeight;
                                  }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByWidth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $scaleWidth = (int) $format->getWidth();
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 cropImage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                                  } else {
                                      // crop higher than format, need more width
                                      $targetWidth = (int) round($cropHeight * $fRatio);
                                      if ($targetWidth > $width) {
                                          $targetWidth = $width;
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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 convertByHeight uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                      Open

                              } else {
                                  $scaleHeight = (int) $format->getHeight();
                              }
                      Severity: Minor
                      Found in src/Sampler.php by phpmd

                      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

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

                              if ($format->isReduceOnly() && $sizeLess) {
                                  // dont crop
                                  if (! $heightLess) {
                                      // resize by height
                                      $scaleHeight = $formatHeight;
                      Severity: Major
                      Found in src/Sampler.php and 1 other location - About 6 hrs to fix
                      src/Sampler.php on lines 170..194

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

                      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

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

                              if ($format->isReduceOnly() && $sizeLess) {
                                  if (! $heightLess) {
                                      // resize by height
                                      $scaleHeight = $formatHeight;
                                      $scaleWidth  = (int) round($scaleHeight * $srcRatio);
                      Severity: Major
                      Found in src/Sampler.php and 1 other location - About 6 hrs to fix
                      src/Sampler.php on lines 111..136

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

                      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