biurad/php-templating

View on GitHub

Showing 20 of 20 total issues

Function generateNodes has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

    public static function generateNodes(string $html): array
    {
        $matchedNodes = $elementNodes = $resolvedNodes = [];
        $html = \preg_replace(['/\n\s*/', '/\s+<\//', '/\"\s+\>/', '/\"\s+\s+/'], [' ', '</', '">', '" '], $html) ?? $html;

Severity: Minor
Found in src/Html/HtmlElement.php - About 6 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 elements.php has 412 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

/*
Severity: Minor
Found in src/Html/elements.php - About 5 hrs to fix

    Function renderAttributes has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function renderAttributes(array $attributes): string
        {
            $attribute = '';
    
            foreach ($attributes as $name => $value) {
    Severity: Minor
    Found in src/Html/HtmlElement.php - About 3 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

    Function find has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        public function find(string $template, RenderInterface &$render = null): ?string
        {
            if ($cachedTemplate = &$this->loadedTemplates[$template] ?? null) {
                [$loadedTemplate, $renderOffset] = $cachedTemplate;
    
    
    Severity: Minor
    Found in src/Template.php - About 3 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

    Function cssFromArray has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function cssFromArray(array $style): ?string
        {
            $result = '';
    
            foreach ($style as $name => $value) {
    Severity: Minor
    Found in src/Html/HtmlElement.php - About 2 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

    Method generateNodes has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function generateNodes(string $html): array
        {
            $matchedNodes = $elementNodes = $resolvedNodes = [];
            $html = \preg_replace(['/\n\s*/', '/\s+<\//', '/\"\s+\>/', '/\"\s+\s+/'], [' ', '</', '">', '" '], $html) ?? $html;
    
    
    Severity: Major
    Found in src/Html/HtmlElement.php - About 2 hrs to fix

      Function findTemplate has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

                      protected function findTemplate(string $name, bool $throw = true): ?string
                      {
                          if (isset($this->cache[$name])) {
                              return $this->cache[$name];
                          }
      Severity: Minor
      Found in src/Renders/TwigRender.php - About 2 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

      Function generateHtml has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function generateHtml(array $elementNodes, callable $resolveNode = null, array $options = []): string
          {
              $content = '';
      
              if (null !== ($indentLevel = $options['indentLevel'] ?? null) && $indentLevel < 2) {
      Severity: Minor
      Found in src/Html/HtmlElement.php - About 2 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

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

          public function parentHas(array $attrNames, AbstractNode $tagNode = null): bool
          {
              if (null !== $tagParent = $this->parent) {
                  foreach ($tagParent->children as $childNode) {
                      if (!$childNode instanceof SelfCloseNode) {
      Severity: Minor
      Found in src/Html/Node/SelfCloseNode.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

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

          public function load(string $template, array $namespaces): ?string
          {
              $fileFailures = [];
      
              if (\file_exists($template)) {
      Severity: Minor
      Found in src/Storage/FilesystemStorage.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 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function render(string $template, array $parameters): string
          {
              $source = self::loadHtml($template) ?? $template;
      
              if ($source !== $template || !\file_exists($template)) {
      Severity: Minor
      Found in src/Renders/TwigRender.php - About 1 hr to fix

        Method find has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function find(string $template, RenderInterface &$render = null): ?string
            {
                if ($cachedTemplate = &$this->loadedTemplates[$template] ?? null) {
                    [$loadedTemplate, $renderOffset] = $cachedTemplate;
        
        
        Severity: Minor
        Found in src/Template.php - About 1 hr to fix

          Method renderAttributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function renderAttributes(array $attributes): string
              {
                  $attribute = '';
          
                  foreach ($attributes as $name => $value) {
          Severity: Minor
          Found in src/Html/HtmlElement.php - About 1 hr to fix

            Method initializeEscapers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function initializeEscapers(): void
                {
                    $flags = \ENT_NOQUOTES | \ENT_SUBSTITUTE;
            
                    $this->escapers = [
            Severity: Minor
            Found in src/Helper/EscaperHelper.php - About 1 hr to fix

              Function doParseNode has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function doParseNode(Node\AbstractNode $tagNode, int $offset, array &$elementNodes, array &$resolvedNodes): void
                  {
                      $lastKey = \array_key_last($elementNodes);
                      $previousNode = null !== $lastKey ? $elementNodes[$lastKey] : null;
              
              
              Severity: Minor
              Found in src/Html/HtmlElement.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

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

                  public function has(array $attrNames, AttributeNode &$attrNode = null): bool
                  {
                      $attrName = null;
              
                      foreach ($this->attributes as $attribute) {
              Severity: Minor
              Found in src/Html/Node/SelfCloseNode.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 forTagWithParent has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public static function forTagWithParent(string $tagName, ?string $attrName = null, ?string $parent = null, bool $first = false, bool $void = false, bool $voidAttr = false): self
              Severity: Minor
              Found in src/Exceptions/ParserException.php - About 45 mins to fix

                Avoid too many return statements within this method.
                Open

                                    return \addcslashes($value, "\x00..\x1F!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~");
                Severity: Major
                Found in src/Helper/EscaperHelper.php - About 30 mins to fix

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

                      public function addLocation(string $location, string $loaderClassName = null): void
                      {
                          if (null !== $loaderClassName) {
                              foreach ($this->loaders as $loader) {
                                  if ($loaderClassName === \get_class($loader)) {
                  Severity: Minor
                  Found in src/Storage/ChainStorage.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 createElement has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      function createElement(string $tag, $attributes = [], bool $selfClosing = null): string
                      {
                          $html = '<' . $tag;
                  
                          if (\is_array($attributes)) {
                  Severity: Minor
                  Found in src/Html/elements.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

                  Severity
                  Category
                  Status
                  Source
                  Language