darylldoyle/svg-sanitizer

View on GitHub
src/Sanitizer.php

Summary

Maintainability
F
3 days
Test Coverage
A
90%

Function startClean has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    protected function startClean(\DOMNodeList $elements, array $elementsToRemove)
    {
        // loop through all elements
        // we do this backwards so we don't skip anything if we delete a node
        // see comments at: http://php.net/manual/en/class.domnamednodemap.php
Severity: Minor
Found in src/Sanitizer.php - About 5 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

File Sanitizer.php has 363 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
namespace enshrined\svgSanitize;

use enshrined\svgSanitize\data\AllowedAttributes;
use enshrined\svgSanitize\data\AllowedTags;
Severity: Minor
Found in src/Sanitizer.php - About 4 hrs to fix

    Sanitizer has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Sanitizer
    {
    
        /**
         * @var \DOMDocument
    Severity: Minor
    Found in src/Sanitizer.php - About 4 hrs to fix

      Method startClean has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function startClean(\DOMNodeList $elements, array $elementsToRemove)
          {
              // loop through all elements
              // we do this backwards so we don't skip anything if we delete a node
              // see comments at: http://php.net/manual/en/class.domnamednodemap.php
      Severity: Major
      Found in src/Sanitizer.php - About 2 hrs to fix

        Function cleanAttributesOnWhitelist has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function cleanAttributesOnWhitelist(\DOMElement $element)
            {
                for ($x = $element->attributes->length - 1; $x >= 0; $x--) {
                    // get attribute name
                    $attrName = $element->attributes->item($x)->nodeName;
        Severity: Minor
        Found in src/Sanitizer.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 isHrefSafeValue has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function isHrefSafeValue($value) {
        
                // Allow empty values
                if (empty($value)) {
                    return true;
        Severity: Minor
        Found in src/Sanitizer.php - About 1 hr to fix

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

              protected function cleanAttributesOnWhitelist(\DOMElement $element)
              {
                  for ($x = $element->attributes->length - 1; $x >= 0; $x--) {
                      // get attribute name
                      $attrName = $element->attributes->item($x)->nodeName;
          Severity: Minor
          Found in src/Sanitizer.php - About 1 hr to fix

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

                public function sanitize($dirty)
                {
                    // Don't run on an empty string
                    if (empty($dirty)) {
                        return '';
            Severity: Minor
            Found in src/Sanitizer.php - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (in_array(strtolower($attrName), ['face', 'color', 'size'])) {
                                          $breaksOutOfForeignContent = true;
                                      }
              Severity: Major
              Found in src/Sanitizer.php - About 45 mins to fix

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

                    protected function isHrefSafeValue($value) {
                
                        // Allow empty values
                        if (empty($value)) {
                            return true;
                Severity: Minor
                Found in src/Sanitizer.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/Sanitizer.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return true;
                  Severity: Major
                  Found in src/Sanitizer.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return true;
                    Severity: Major
                    Found in src/Sanitizer.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return false;
                      Severity: Major
                      Found in src/Sanitizer.php - About 30 mins to fix

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

                            protected function cleanUnsafeNodes(\DOMNode $currentElement) {
                                // Replace CDATA node with encoded text node
                                if ($currentElement instanceof \DOMCdataSection) {
                                    $textNode = $currentElement->ownerDocument->createTextNode($currentElement->nodeValue);
                                    $currentElement->parentNode->replaceChild($textNode, $currentElement);
                        Severity: Minor
                        Found in src/Sanitizer.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

                        There are no issues that match your filters.

                        Category
                        Status