meyfa/php-svg

View on GitHub

Showing 42 of 54 total issues

Method fromFile has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        string $path,
        string $mimeType,
        $x = null,
        $y = null,
        $width = null,
Severity: Minor
Found in src/Nodes/Embedded/SVGImage.php - About 45 mins to fix

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

        public function __construct(?string $href = null, $x = null, $y = null, $width = null, $height = null)
    Severity: Minor
    Found in src/Nodes/Embedded/SVGImage.php - About 35 mins to fix

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

          protected function prepareRenderParams(array $options, Transform $transform, ?FontRegistry $fontRegistry): ?array
          {
              // this assumes there is no rotation or skew, but that's fine, we can't deal with that anyway
              $size1 = $options['fontSize'];
              $size2 = $size1;
      Severity: Minor
      Found in src/Rasterization/Renderers/TextRenderer.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 approximate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function approximate(array $commands): void
          {
              // https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands
              // "A path data segment (if there is one) must begin with a "moveto" command."
              if (empty($commands) || ($commands[0]['id'] !== 'M' && $commands[0]['id'] !== 'm')) {
      Severity: Minor
      Found in src/Rasterization/Path/PathApproximator.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 true;
      Severity: Major
      Found in src/Rasterization/Path/PathParser.php - About 30 mins to fix

        The method toXMLString has a boolean flag argument $standalone, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function toXMLString(bool $standalone = true): string
        Severity: Minor
        Found in src/SVG.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

        Missing class import via use statement (line '13', column '23').
        Open

                    throw new \RuntimeException('Font file "' . $filePath . '" is not a valid TrueType font.');
        Severity: Minor
        Found in src/Fonts/FontRegistry.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        The method __construct has a boolean flag argument $isStandalone, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function __construct(bool $isStandalone = true)
        Severity: Minor
        Found in src/Writing/SVGWriter.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

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

            protected function prepareRenderParams(array $options, Transform $transform, ?FontRegistry $fontRegistry): ?array
            {
                $w = $options['width'];
                $h = $options['height'];
                $transform->resize($w, $h);
        Severity: Minor
        Found in src/Rasterization/Renderers/RectRenderer.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

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

            public static function parseCss(string $css): array
            {
                $result = [];
                preg_match_all('/(?ims)([a-z0-9\s\,\.\:#_\-@^*()\[\]\"\'=]+)\{([^\}]*)\}/', $css, $arr);
        
        
        Severity: Minor
        Found in src/Utilities/SVGStyleParser.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

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

            private static function joinPoints(array $pointsArray): string
            {
                $pointsString = '';
                foreach ($pointsArray as $point) {
                    if (count($point) < 2) {
        Severity: Minor
        Found in src/Nodes/Shapes/SVGPolygonalShape.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

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

            public function writeNode(SVGNode $node): void
            {
                $this->outString .= '<' . $node->getName();
        
                $this->appendNamespaces($node->getSerializableNamespaces());
        Severity: Minor
        Found in src/Writing/SVGWriter.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

        Avoid unused parameters such as '$encodingID'.
        Open

            private static function decodeString(string $string, int $platformID, int $encodingID): string
        Severity: Minor
        Found in src/Fonts/TrueTypeFontFile.php by phpmd

        UnusedFormalParameter

        Since: 0.2

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

        Example

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

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

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

                $version = self::uint16($file);
        Severity: Minor
        Found in src/Fonts/TrueTypeFontFile.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

        TODO found
        Open

                // TODO support "auto" values for width and height

        TODO found
        Confirmed

                // TODO: support percentage font sizes
        Severity: Minor
        Found in src/Nodes/Texts/SVGText.php by fixme

        TODO found
        Open

                // TODO implement generic families ('serif', 'sans-serif', 'monospace', etc.)
        Severity: Minor
        Found in src/Fonts/FontRegistry.php by fixme

        TODO found
        Open

                    // TODO remove this workaround
        Severity: Minor
        Found in src/Nodes/Texts/SVGText.php by fixme

        TODO found
        Open

                // TODO implement "bolder" and "lighter"

        TODO found
        Open

                        // TODO: implement
        Severity: Minor
        Found in src/Fonts/TrueTypeFontFile.php by fixme
        Severity
        Category
        Status
        Source
        Language