meyfa/php-svg

View on GitHub

Showing 27 of 54 total issues

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

                              Function getElementById has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function getElementById(string $id): ?SVGNode
                                  {
                                      // start with document
                                      $stack = [$this];
                              
                              
                              Severity: Minor
                              Found in src/Nodes/Structures/SVGDocumentFragment.php - About 45 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 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
                                Severity
                                Category
                                Status
                                Source
                                Language