pug-php/twig

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

Summary

Maintainability
B
5 hrs
Test Coverage
A
97%

The class TwigXmlFormat has an overall complexity of 51 which is very high. The configured complexity threshold is 50.
Open

class TwigXmlFormat extends AbstractTwigFormat
{
    use AssignmentHelpersTrait;

    const DOCTYPE = '<?xml version="1.0" encoding="utf-8" ?>';

Function formatAttributeElement has a Cognitive Complexity of 15 (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/Format/TwigXmlFormat.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 formatAssignmentElement has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function formatAssignmentElement(AssignmentElement $element)
    {
        $handlers = $this->getOption('assignment_handlers');
        $newElements = [];
        array_walk(
Severity: Minor
Found in src/Phug/Formatter/Format/TwigXmlFormat.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);
    
            $defaults = [];
    Severity: Minor
    Found in src/Phug/Formatter/Format/TwigXmlFormat.php - About 1 hr 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/Format/TwigXmlFormat.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return '';
        Severity: Major
        Found in src/Phug/Formatter/Format/TwigXmlFormat.php - About 30 mins to fix

          The method formatAttributeElement() has an NPath complexity of 325. The configured NPath complexity threshold is 200.
          Open

              protected function formatAttributeElement(AttributeElement $element)
              {
                  $value = $element->getValue();
                  $name = $element->getName();
                  $nonEmptyAttribute = ($name === 'class' || $name === 'id');

          NPathComplexity

          Since: 0.1

          The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

          Example

          class Foo {
              function bar() {
                  // lots of complicated code
              }
          }

          Source https://phpmd.org/rules/codesize.html#npathcomplexity

          The method formatAttributeElement() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
          Open

              protected function formatAttributeElement(AttributeElement $element)
              {
                  $value = $element->getValue();
                  $name = $element->getName();
                  $nonEmptyAttribute = ($name === 'class' || $name === 'id');

          CyclomaticComplexity

          Since: 0.1

          Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

          Example

          // Cyclomatic Complexity = 11
          class Foo {
          1   public function example() {
          2       if ($a == $b) {
          3           if ($a1 == $b1) {
                          fiddle();
          4           } elseif ($a2 == $b2) {
                          fiddle();
                      } else {
                          fiddle();
                      }
          5       } elseif ($c == $d) {
          6           while ($c == $d) {
                          fiddle();
                      }
          7        } elseif ($e == $f) {
          8           for ($n = 0; $n < $h; $n++) {
                          fiddle();
                      }
                  } else {
                      switch ($z) {
          9               case 1:
                              fiddle();
                              break;
          10              case 2:
                              fiddle();
                              break;
          11              case 3:
                              fiddle();
                              break;
                          default:
                              fiddle();
                              break;
                      }
                  }
              }
          }

          Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

          Avoid unused parameters such as '$element'.
          Open

              public function isWhiteSpaceSensitive(MarkupInterface $element)

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$element'.
          Open

              protected function isBlockTag(MarkupInterface $element)

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Parameter $element has undeclared type \Phug\Formatter\MarkupInterface
          Open

              public function isSelfClosingTag(MarkupInterface $element, $isSelfClosing = null)

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                          $this->pattern(

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
          Open

                      $formattedValue = $this->format($value);

          Argument 1 (element) is \Phug\Formatter\Element\MarkupElement but \Phug\Formatter\Format\TwigXmlFormat::isWhiteSpaceSensitive() takes \Phug\Formatter\MarkupInterface defined at /code/src/Phug/Formatter/Format/TwigXmlFormat.php:123
          Open

                      !$this->isWhiteSpaceSensitive($element)

          Call to method hasChildren from undeclared class \Phug\Formatter\Element\MarkupElement
          Open

                      $element->hasChildren()

          Call to method getAttributes from undeclared class \Phug\Formatter\Element\AssignmentElement
          Open

                          $attributes = iterator_to_array($attributesAssignment->getAttributes());

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::registerHelper
          Open

                  return $this->registerHelper('available_attribute_assignments', $availableAssignments);

          Call to method getChildren from undeclared class \Phug\Formatter\MarkupInterface
          Open

                      $visibleChildren = array_filter($element->getChildren(), function ($child) {

          Checking instanceof against undeclared class \Phug\Formatter\Element\TextElement
          Open

                              !($child instanceof TextElement) ||

          Checking instanceof against undeclared class \Phug\Formatter\Element\TextElement
          Open

                  if ($value instanceof TextElement && $nonEmptyAttribute && (!$value->getValue() || $value->getValue() === '')) {

          Call to method getValue from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                      if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'])) {

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getIndent
          Open

                          ? $this->getNewLine().'%s'.$this->getIndent()

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getNewLine
          Open

                          ? $this->getNewLine().'%s'.$this->getIndent()

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                  return $this->pattern(

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getOption
          Open

                  $handlers = $this->getOption('assignment_handlers');

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatCode
          Open

                                  $arguments[] = $this->formatCode($value, $checked);

          Call to method getName from undeclared class \Phug\Formatter\Element\AttributeElement
          Open

                  $name = $element->getName();

          Checking instanceof against undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                  if ($name instanceof ExpressionElement) {

          Call to method isChecked from undeclared class \Phug\Formatter\Element\AbstractValueElement
          Open

                                  $checked = method_exists($value, 'isChecked') && $value->isChecked();

          Call to method getName from undeclared class \Phug\Formatter\MarkupInterface
          Open

                              '<'.$element->getName().'/> but contains nested content.',

          Checking instanceof against undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                  if ($value instanceof ExpressionElement) {

          Parameter $element has undeclared type \Phug\Formatter\Element\MarkupElement
          Open

              protected function formatPairTagChildren(MarkupElement $element)

          Call to method getChildAt from undeclared class \Phug\Formatter\Element\MarkupElement
          Open

                  $firstChild = $element->getChildAt(0);

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::setOptionsDefaults
          Open

                  $this

          Call to method hasChildren from undeclared class \Phug\Formatter\MarkupInterface
          Open

                  if ($isSelfClosing && $element->hasChildren()) {

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getHelper
          Open

                  $availableAssignments = $this->getHelper('available_attribute_assignments');

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                      $bufferVariable = $this->pattern('buffer_variable');

          Parameter $element has undeclared type \Phug\Formatter\Element\MarkupElement
          Open

              protected function formatPairTag($open, $close, MarkupElement $element)

          Call to undeclared method format in callable. Possible object type(s) for that method are \Phug\Formatter\Format\TwigXmlFormat
          Open

                  return implode('', array_map([$this, 'format'], $newElements));

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
          Open

                      $this->format($name),

          Checking instanceof against undeclared class \Phug\Formatter\Element\CodeElement
          Open

                              $firstChild instanceof CodeElement &&

          Argument 1 (element) is \Phug\Formatter\Element\MarkupElement but \Phug\Formatter\Format\TwigXmlFormat::isBlockTag() takes \Phug\Formatter\MarkupInterface defined at /code/src/Phug/Formatter/Format/TwigXmlFormat.php:118
          Open

                              $this->isBlockTag($element)

          Parameter $attributesAssignment has undeclared type \Phug\Formatter\Element\AssignmentElement
          Open

                      function (AssignmentElement $attributesAssignment) use (&$arguments, $markup) {

          Class uses undeclared trait \Phug\Formatter\Partial\AssignmentHelpersTrait
          Open

          class TwigXmlFormat extends AbstractTwigFormat

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::provideArrayEscape (Did you mean expr->provideTwigArrayEscape())
          Open

                  return $this->provideArrayEscape();

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::registerHelper
          Open

                  $this->registerHelper($name.'_attribute_assignment', $handler);

          Call to method isAutoClosed from undeclared class \Phug\Formatter\MarkupInterface
          Open

                      $isSelfClosing = $element->isAutoClosed();

          Parameter $element has undeclared type \Phug\Formatter\ElementInterface
          Open

              public function __invoke(ElementInterface $element)

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatAttributeAsArrayItem
          Open

                          $arguments[] = $this->formatAttributeAsArrayItem($attribute);

          Call to method getValue from undeclared class \Phug\Formatter\Element\TextElement
          Open

                              trim($child->getValue()) !== ''

          Parameter $formatter has undeclared type ?\Phug\Formatter
          Open

              public function __construct(Formatter $formatter = null)

          Call to method getValue from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                      if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"])) {

          Call to method getValue from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                      if (strtolower($value->getValue()) === 'true') {

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                  return $this->pattern(

          Call to method hasOption from undeclared class \Phug\Formatter
          Open

                      $defaults[$option] = ($formatter->hasOption($option) ? $formatter->getOption($option) : null) ?: [];

          Reference to undeclared constant \Phug\Formatter\Format\TwigXmlFormat::SAVE_VALUE
          Open

                          'save_value'                => static::SAVE_VALUE,

          Parameter $element has undeclared type \Phug\Formatter\MarkupInterface
          Open

              public function isWhiteSpaceSensitive(MarkupInterface $element)

          Parameter $element has undeclared type \Phug\Formatter\Element\AttributeElement
          Open

              protected function formatAttributeElement(AttributeElement $element)

          Call to method getValue from undeclared class \Phug\Formatter\Element\TextElement
          Open

                  if ($value instanceof TextElement && $nonEmptyAttribute && (!$value->getValue() || $value->getValue() === '')) {

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                  return $this->pattern(

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getOption
          Open

                  $handlers = $this->getOption('attribute_assignments');

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
          Open

                  return $this->format($element);

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::throwException
          Open

                          $this->throwException(

          Call to method getName from undeclared class \Phug\Formatter\MarkupInterface
          Open

                              $element->getName().' is a self closing element: '.

          Parameter $element has undeclared type \Phug\Formatter\MarkupInterface
          Open

              protected function isBlockTag(MarkupInterface $element)

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
          Open

                      $this->format($value)

          Call to method getValue from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                              $this->formatCode($name->getValue(), $name->isChecked())

          Argument 1 (element) is \Phug\Formatter\Element\MarkupElement but \Phug\Formatter\Format\TwigXmlFormat::formatElementChildren() takes \Phug\Formatter\ElementInterface defined at /code/src/Phug/Formatter/AbstractTwigFormat.php:143
          Open

                      $this->formatElementChildren($element)

          Call to method getContainer from undeclared class \Phug\Formatter\Element\AssignmentElement
          Open

                  $markup = $element->getContainer();

          Call to method getValue from undeclared class \Phug\Formatter\Element\AbstractValueElement
          Open

                                      $value = $value->getValue();

          Call to method getOption from undeclared class \Phug\Formatter
          Open

                      $defaults[$option] = ($formatter->hasOption($option) ? $formatter->getOption($option) : null) ?: [];

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
          Open

                      $name = $this->pattern(

          Call to method isChecked from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                              $this->formatCode($name->getValue(), $name->isChecked())

          Parameter $element has undeclared type \Phug\Formatter\Element\AssignmentElement
          Open

              protected function formatAssignmentElement(AssignmentElement $element)

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::attributesAssignmentsFromPairs
          Open

                      $newElements[] = $this->attributesAssignmentsFromPairs($arguments);

          Call to method getValue from undeclared class \Phug\Formatter\Element\AttributeElement
          Open

                  $value = $element->getValue();

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatCode
          Open

                              $this->formatCode($name->getValue(), $name->isChecked())

          Call to method __construct from undeclared class \Phug\Formatter\Element\ExpressionElement
          Open

                      $value = new ExpressionElement($bufferVariable);

          Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
          Open

                  $formattedName = $this->format($name);

          Checking instanceof against undeclared class \Phug\Formatter\MarkupInterface
          Open

                              $firstChild instanceof MarkupInterface &&

          Parameter $attribute has undeclared type \Phug\Formatter\Element\AbstractValueElement
          Open

                              function (AbstractValueElement $attribute) use (&$arguments) {

          Parameter $attribute has undeclared type \Phug\Formatter\Element\AttributeElement
          Open

                      function (AttributeElement $attribute) use (&$arguments) {

          There are no issues that match your filters.

          Category
          Status