elboletaire/Watimage

View on GitHub

Showing 57 of 57 total issues

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

    public function __construct($file = null, $options = [])
    {
        if (!empty($options)) {
            foreach ($options as $option => $values) {
                $method = 'set' . ucfirst($option);
Severity: Minor
Found in src/Watermark.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

Avoid too many return statements within this method.
Open

                return $this->rotate(90);
Severity: Major
Found in src/Image.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

                    return $this;
    Severity: Major
    Found in src/Image.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return $this->rotate(-90);
      Severity: Major
      Found in src/Image.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return $this->rotate(-90);
        Severity: Major
        Found in src/Image.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return $this->rotate(90);
          Severity: Major
          Found in src/Image.php - About 30 mins to fix

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

                public function generate($filename = null, $output = null, $header = true)
                {
                    $output = $output ?: $this->metadata['mime'];
                    if (!empty($filename)) {
                        $output = $this->getMimeFromExtension($filename);
            Severity: Minor
            Found in src/Image.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 class Image has 1192 lines of code. Current threshold is 1000. Avoid really long classes.
            Open

            class Image
            {
                /**
                 * Constant for the (deprecated) transparent color
                 */
            Severity: Minor
            Found in src/Image.php by phpmd

            Avoid unused local variables such as '$height'.
            Open

                    if (!isset($oy, $dx, $dy, $width, $height) && is_array($ox)) {
            Severity: Minor
            Found in src/Normalize.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

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

            The method color() has an NPath complexity of 336. The configured NPath complexity threshold is 200.
            Open

                public static function color($color)
                {
                    if ($color === Image::COLOR_TRANSPARENT) {
                        return [
                            'r' => 0,
            Severity: Minor
            Found in src/Normalize.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

            Avoid unused local variables such as '$width'.
            Open

                    if (!isset($oy, $dx, $dy, $width, $height) && is_array($ox)) {
            Severity: Minor
            Found in src/Normalize.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

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

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

                protected function calculateSize($metadata)
                {
                    if (!isset($this->size)) {
                        return;
                    }
            Severity: Minor
            Found in src/Watermark.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 color() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
            Open

                public static function color($color)
                {
                    if ($color === Image::COLOR_TRANSPARENT) {
                        return [
                            'r' => 0,
            Severity: Minor
            Found in src/Normalize.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 calculatePosition() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
            Open

                protected function calculatePosition($metadata)
                {
                    // Force center alignement if 'full' size has been set
                    if ($this->size == 'full') {
                        $this->position = 'center center';
            Severity: Minor
            Found in src/Watermark.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 flip() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
            Open

                public static function flip($type)
                {
                    switch (strtolower($type)) {
                        case 'x':
                        case 'h':
            Severity: Minor
            Found in src/Normalize.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 size() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
            Open

                public static function size($width, $height = null)
                {
                    if (!isset($height) && is_array($width)) {
                        $allowedKeys = [
                            [0, 1],
            Severity: Minor
            Found in src/Normalize.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

            TODO found
            Open

                 * TODO: Create an additional class with instagram-like effects and move it there.
            Severity: Minor
            Found in src/Image.php by fixme
            Severity
            Category
            Status
            Source
            Language