phug-php/formatter

View on GitHub
Formatter/Format/XmlFormat.php

Summary

Maintainability
D
2 days
Test Coverage

File XmlFormat.php has 448 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Phug\Formatter\Format;

use Closure;
Severity: Minor
Found in Formatter/Format/XmlFormat.php - About 6 hrs to fix

    Method yieldAssignmentElement has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function yieldAssignmentElement(AssignmentElement $element)
        {
            foreach ($this->getOption('assignment_handlers') as $handler) {
                $iterator = $handler($element) ?: [];
    
    
    Severity: Major
    Found in Formatter/Format/XmlFormat.php - About 2 hrs to fix

      XmlFormat has 24 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class XmlFormat extends AbstractFormat
      {
          use AssignmentHelpersTrait;
      
          const DOCTYPE = '<?xml version="1.0" encoding="utf-8" ?>';
      Severity: Minor
      Found in Formatter/Format/XmlFormat.php - About 2 hrs to fix

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

            protected function formatAttributeElement(AttributeElement $element)
            {
                $value = $element->getValue();
                $name = $element->getName();
                $nonEmptyAttribute = ($name === 'class' || $name === 'id');
        Severity: Minor
        Found in Formatter/Format/XmlFormat.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 formatAttributeElement has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function formatAttributeElement(AttributeElement $element)
            {
                $value = $element->getValue();
                $name = $element->getName();
                $nonEmptyAttribute = ($name === 'class' || $name === 'id');
        Severity: Minor
        Found in Formatter/Format/XmlFormat.php - About 1 hr to fix

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

              protected function hasNonStaticAttributes(MarkupInterface $element)
              {
                  if ($element instanceof MarkupElement || $element instanceof MixinCallElement) {
                      foreach ($element->getAttributes() as $attribute) {
                          if ($attribute->hasStaticMember('value')) {
          Severity: Minor
          Found in Formatter/Format/XmlFormat.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 yieldAssignmentElement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function yieldAssignmentElement(AssignmentElement $element)
              {
                  foreach ($this->getOption('assignment_handlers') as $handler) {
                      $iterator = $handler($element) ?: [];
          
          
          Severity: Minor
          Found in Formatter/Format/XmlFormat.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 __construct has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function __construct(Formatter $formatter = null)
              {
                  parent::__construct($formatter);
          
                  $this
          Severity: Minor
          Found in Formatter/Format/XmlFormat.php - About 1 hr to fix

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

                protected function hasDuplicateAttributeNames(MarkupInterface $element)
                {
                    if ($element instanceof MarkupElement || $element instanceof MixinCallElement) {
                        $names = [];
                        foreach ($element->getAttributes() as $attribute) {
            Severity: Minor
            Found in Formatter/Format/XmlFormat.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 formatAttributes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function formatAttributes(MarkupElement $element)
                {
                    if ($this->hasNonStaticAttributes($element) ||
                        $this->hasDuplicateAttributeNames($element)) {
                        $empty = true;
            Severity: Minor
            Found in Formatter/Format/XmlFormat.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

            Consider simplifying this complex logical expression.
            Open

                    if ($nonEmptyAttribute && (
                        !$value ||
                        ($value instanceof TextElement && ((string) $value->getValue()) === '') ||
                        (is_string($value) && in_array(trim($value), ['', '""', "''"], true))
                    )) {
            Severity: Major
            Found in Formatter/Format/XmlFormat.php - About 40 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $this->pattern(
                          'attribute_pattern',
                          $this->format($name),
                          $this->format($value)
                      );
              Severity: Major
              Found in Formatter/Format/XmlFormat.php - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status