hnhdigital-os/laravel-html-builder

View on GitHub
src/Tag.php

Summary

Maintainability
D
2 days
Test Coverage

File Tag.php has 305 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace HnhDigital\LaravelHtmlBuilder;

use HnhDigital\LaravelHtmlGenerator\Html;
Severity: Minor
Found in src/Tag.php - About 3 hrs to fix

    Tag has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Tag
    {
        private static $tag_registry = [];
        private static $special_tags = [
            'img', 'br', 'hr', 'input', 'area', 'link', 'meta', 'param',
    Severity: Minor
    Found in src/Tag.php - About 3 hrs to fix

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

          private static function buildHtml(&$html, $tag_object, $options, $tab = 0)
          {
              self::checkBuildOptions($options);
      
              $tag_is_special = in_array($tag_object->getTag(), self::$special_tags);
      Severity: Minor
      Found in src/Tag.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 buildArray has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function buildArray(&$array, $tag_object, $options = [])
          {
              self::checkBuildOptions($options);
      
              if (in_array($tag_object->getTag(), self::$special_tags)) {
      Severity: Minor
      Found in src/Tag.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 add has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          public function add($tag, ...$arguments)
          {
              $tag = strtolower($tag);
              $text = '';
              $attributes = [];
      Severity: Minor
      Found in src/Tag.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 buildHtml has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function buildHtml(&$html, $tag_object, $options, $tab = 0)
          {
              self::checkBuildOptions($options);
      
              $tag_is_special = in_array($tag_object->getTag(), self::$special_tags);
      Severity: Minor
      Found in src/Tag.php - About 1 hr to fix

        Method add has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function add($tag, ...$arguments)
            {
                $tag = strtolower($tag);
                $text = '';
                $attributes = [];
        Severity: Minor
        Found in src/Tag.php - About 1 hr to fix

          Method buildFromArray has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function buildFromArray(&$html, $array, $tab = 0)
              {
                  $pad = '';
                  if ($tab > 0) {
                      $pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
          Severity: Minor
          Found in src/Tag.php - About 1 hr to fix

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

                private static function buildHtmlAttribute($attributes)
                {
                    $html = '';
                    foreach ($attributes as $name => $value) {
                        if (is_array($value)) {
            Severity: Minor
            Found in src/Tag.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

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

                public static function buildFromArray(&$html, $array, $tab = 0)
                {
                    $pad = '';
                    if ($tab > 0) {
                        $pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
            Severity: Minor
            Found in src/Tag.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

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

                        throw new \Exception(
            Severity: Minor
            Found in src/Tag.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

            Missing class import via use statement (line '544', column '19').
            Open

                    throw new \Exception($this->tag.' does permit '.$tag);
            Severity: Minor
            Found in src/Tag.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

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

                        throw new \Exception($tag.' does not exist.');
            Severity: Minor
            Found in src/Tag.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

            Missing class import via use statement (line '106', column '19').
            Open

                    throw new \Exception($this->tag.' does permit '.$tag);
            Severity: Minor
            Found in src/Tag.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

            There are no issues that match your filters.

            Category
            Status