phug-php/phug

View on GitHub
src/Phug/Formatter/Formatter/Format/XmlFormat.php

Summary

Maintainability
D
2 days
Test Coverage
A
100%

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

<?php

namespace Phug\Formatter\Format;

use Phug\Formatter;
Severity: Minor
Found in src/Phug/Formatter/Formatter/Format/XmlFormat.php - About 3 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 src/Phug/Formatter/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 src/Phug/Formatter/Formatter/Format/XmlFormat.php - About 1 hr to fix

      Function yieldAssignmentElement has a Cognitive Complexity of 13 (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 src/Phug/Formatter/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 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 src/Phug/Formatter/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 yieldAssignmentElement has 33 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: Minor
      Found in src/Phug/Formatter/Formatter/Format/XmlFormat.php - About 1 hr to fix

        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 src/Phug/Formatter/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 src/Phug/Formatter/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 src/Phug/Formatter/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 && ($value->getValue() ?: '') === '') ||
                      (is_string($value) && in_array(trim($value), ['', '""', "''"]))
                  )) {
          Severity: Major
          Found in src/Phug/Formatter/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 src/Phug/Formatter/Formatter/Format/XmlFormat.php - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status