meyfa/php-svg

View on GitHub

Showing 42 of 54 total issues

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

<?php

namespace SVG\Nodes\Shapes;

use SVG\Nodes\SVGNodeContainer;
Severity: Major
Found in src/Nodes/Shapes/SVGLine.php and 1 other location - About 2 days to fix
src/Nodes/Shapes/SVGEllipse.php on lines 1..139

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

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

<?php

namespace SVG\Nodes\Shapes;

use SVG\Nodes\SVGNodeContainer;
Severity: Major
Found in src/Nodes/Shapes/SVGEllipse.php and 1 other location - About 2 days to fix
src/Nodes/Shapes/SVGLine.php on lines 1..139

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

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

SVGNode has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class SVGNode
{
    /**
     * @var SVGNodeContainer $parent The parent node.
     */
Severity: Minor
Found in src/Nodes/SVGNode.php - About 2 hrs to fix

    Method renderStrokeRounded has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function renderStrokeRounded($image, array $params, int $color, float $strokeWidth): void
        {
            $x1 = $params['x1'];
            $y1 = $params['y1'];
            $x2 = $params['x2'];
    Severity: Minor
    Found in src/Rasterization/Renderers/RectRenderer.php - About 1 hr to fix

      Function applyAttributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          private function applyAttributes(SVGNode $node, SimpleXMLElement $xml, array $namespaces): void
          {
              foreach ($namespaces as $ns) {
                  foreach ($xml->attributes($ns, true) as $key => $value) {
                      if ($key === 'style') {
      Severity: Minor
      Found in src/Reading/SVGReader.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 renderStroke has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function renderStroke($image, $params, int $color, float $strokeWidth): void
          {
              imagesetthickness($image, round($strokeWidth));
      
              if ($params['rx'] != 0 || $params['ry'] != 0) {
      Severity: Minor
      Found in src/Rasterization/Renderers/RectRenderer.php - About 1 hr to fix

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

            private static function endpointToCenter(
                array $start,
                array $end,
                bool $large,
                bool $sweep,
        Severity: Minor
        Found in src/Rasterization/Path/ArcApproximator.php - About 1 hr to fix

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

              public function getElementsByClassName($className, array &$result = []): array
              {
                  if (!is_array($className)) {
                      $className = preg_split('/\s+/', Str::trim($className));
                  }
          Severity: Minor
          Found in src/Nodes/SVGNodeContainer.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 prepareRenderParams has 32 lines of code (exceeds 25 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 1 hr to fix

            Method prepareRenderParams has 31 lines of code (exceeds 25 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 1 hr to fix

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

                  private function parseCommandChain(string $id, array $args, array &$commands): bool
                  {
                      if (!isset(self::$commandLengths[$id])) {
                          // unknown command
                          return false;
              Severity: Minor
              Found in src/Rasterization/Path/PathParser.php - About 1 hr to fix

                Function parseCommandChain has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function parseCommandChain(string $id, array $args, array &$commands): bool
                    {
                        if (!isset(self::$commandLengths[$id])) {
                            // unknown command
                            return false;
                Severity: Minor
                Found in src/Rasterization/Path/PathParser.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 render has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function render(SVGRasterizer $rasterizer, array $options, SVGNode $context): void
                    {
                        $transform = $rasterizer->getCurrentTransform();
                
                        $x      = $options['x'] ?? 0;
                Severity: Minor
                Found in src/Rasterization/Renderers/ImageRenderer.php - About 1 hr to fix

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

                      public function approximate(
                          array $start,
                          array $end,
                          bool $large,
                          bool $sweep,
                  Severity: Minor
                  Found in src/Rasterization/Path/ArcApproximator.php - About 1 hr to fix

                    Method approximate has 8 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                            array $start,
                            array $end,
                            bool $large,
                            bool $sweep,
                            float $radiusX,
                    Severity: Major
                    Found in src/Rasterization/Path/ArcApproximator.php - About 1 hr to fix

                      Method endpointToCenter has 8 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              array $start,
                              array $end,
                              bool $large,
                              bool $sweep,
                              float $radiusX,
                      Severity: Major
                      Found in src/Rasterization/Path/ArcApproximator.php - About 1 hr to fix

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

                            private function closestMatchBasedOnWeight(callable $filter, float $targetWeight): ?FontFile
                            {
                                $bestMatch = null;
                                foreach ($this->fontFiles as $font) {
                                    if (!$filter($font)) {
                        Severity: Minor
                        Found in src/Fonts/FontRegistry.php - About 55 mins to fix

                        Cognitive Complexity

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

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

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

                        Further reading

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

                                ?string $docWidth,
                                ?string $docHeight,
                                ?array $viewBox,
                                int $width,
                                int $height,
                        Severity: Minor
                        Found in src/Rasterization/SVGRasterizer.php - About 45 mins to fix

                          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 fromString has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

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