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" ?>';
- Exclude checks
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');
- Read upRead up
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(
Method __construct
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(Formatter $formatter = null)
{
parent::__construct($formatter);
$defaults = [];
Avoid too many return
statements within this method. Open
return $this->pattern(
'attribute_pattern',
$this->format($name),
$this->format($value)
);
Avoid too many return
statements within this method. Open
return '';
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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
protected function isBlockTag(MarkupInterface $element)
- Read upRead up
- Exclude checks
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
public function isWhiteSpaceSensitive(MarkupInterface $element)
- Read upRead up
- Exclude checks
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)
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
if (strtolower($value->getValue()) === 'true') {
- Exclude checks
Call to method __construct
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
$value = new ExpressionElement($bufferVariable);
- Exclude checks
Call to method getName
from undeclared class \Phug\Formatter\Element\AttributeElement
Open
$name = $element->getName();
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
return $this->pattern(
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
Open
$this->format($name),
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
Open
$this->format($value)
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\Element\CodeElement
Open
$firstChild instanceof CodeElement &&
- Exclude checks
Parameter $attributesAssignment
has undeclared type \Phug\Formatter\Element\AssignmentElement
Open
function (AssignmentElement $attributesAssignment) use (&$arguments, $markup) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::registerHelper
Open
$this->registerHelper($name.'_attribute_assignment', $handler);
- Exclude checks
Parameter $attribute
has undeclared type \Phug\Formatter\Element\AbstractValueElement
Open
function (AbstractValueElement $attribute) use (&$arguments) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
$name = $this->pattern(
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\MarkupInterface
Open
$firstChild instanceof MarkupInterface &&
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\Element\MarkupElement
Open
protected function formatPairTag($open, $close, MarkupElement $element)
- Exclude checks
Parameter $attribute
has undeclared type \Phug\Formatter\Element\AttributeElement
Open
function (AttributeElement $attribute) use (&$arguments) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
return $this->pattern(
- Exclude checks
Call to method getContainer
from undeclared class \Phug\Formatter\Element\AssignmentElement
Open
$markup = $element->getContainer();
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatAttributeAsArrayItem
Open
$arguments[] = $this->formatAttributeAsArrayItem($attribute);
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getNewLine
Open
? $this->getNewLine().'%s'.$this->getIndent()
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getHelper
Open
$availableAssignments = $this->getHelper('available_attribute_assignments');
- Exclude checks
Call to method hasOption
from undeclared class \Phug\Formatter
Open
$defaults[$option] = ($formatter->hasOption($option) ? $formatter->getOption($option) : null) ?: [];
- Exclude checks
Call to method getChildren
from undeclared class \Phug\Formatter\MarkupInterface
Open
$visibleChildren = array_filter($element->getChildren(), function ($child) {
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\TextElement
Open
if ($value instanceof TextElement && $nonEmptyAttribute && (!$value->getValue() || $value->getValue() === '')) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
Open
$formattedValue = $this->format($value);
- Exclude checks
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)
- Exclude checks
Parameter $formatter
has undeclared type ?\Phug\Formatter
Open
public function __construct(Formatter $formatter = null)
- Exclude checks
Call to method getOption
from undeclared class \Phug\Formatter
Open
$defaults[$option] = ($formatter->hasOption($option) ? $formatter->getOption($option) : null) ?: [];
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\ElementInterface
Open
public function __invoke(ElementInterface $element)
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getOption
Open
$handlers = $this->getOption('attribute_assignments');
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::provideArrayEscape
(Did you mean expr->provideTwigArrayEscape()) Open
return $this->provideArrayEscape();
- Exclude checks
Call to method isAutoClosed
from undeclared class \Phug\Formatter\MarkupInterface
Open
$isSelfClosing = $element->isAutoClosed();
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\MarkupInterface
Open
public function isWhiteSpaceSensitive(MarkupInterface $element)
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\Element\TextElement
Open
!($child instanceof TextElement) ||
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\AttributeElement
Open
$value = $element->getValue();
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
$bufferVariable = $this->pattern('buffer_variable');
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatCode
Open
$this->formatCode($name->getValue(), $name->isChecked())
- Exclude checks
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)
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\TextElement
Open
trim($child->getValue()) !== ''
- Exclude checks
Call to method getName
from undeclared class \Phug\Formatter\MarkupInterface
Open
$element->getName().' is a self closing element: '.
- Exclude checks
Call to method getChildAt
from undeclared class \Phug\Formatter\Element\MarkupElement
Open
$firstChild = $element->getChildAt(0);
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getOption
Open
$handlers = $this->getOption('assignment_handlers');
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::formatCode
Open
$arguments[] = $this->formatCode($value, $checked);
- Exclude checks
Call to method hasChildren
from undeclared class \Phug\Formatter\MarkupInterface
Open
if ($isSelfClosing && $element->hasChildren()) {
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
$this->formatCode($name->getValue(), $name->isChecked())
- Exclude checks
Call to method isChecked
from undeclared class \Phug\Formatter\Element\AbstractValueElement
Open
$checked = method_exists($value, 'isChecked') && $value->isChecked();
- Exclude checks
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));
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
Open
return $this->format($element);
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::throwException
Open
$this->throwException(
- Exclude checks
Call to method getName
from undeclared class \Phug\Formatter\MarkupInterface
Open
'<'.$element->getName().'/> but contains nested content.',
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\Element\ExpressionElement
Open
if ($value instanceof ExpressionElement) {
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"])) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::getIndent
Open
? $this->getNewLine().'%s'.$this->getIndent()
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::attributesAssignmentsFromPairs
Open
$newElements[] = $this->attributesAssignmentsFromPairs($arguments);
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::format
Open
$formattedName = $this->format($name);
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
return $this->pattern(
- Exclude checks
Call to method getAttributes
from undeclared class \Phug\Formatter\Element\AssignmentElement
Open
$attributes = iterator_to_array($attributesAssignment->getAttributes());
- Exclude checks
Class uses undeclared trait \Phug\Formatter\Partial\AssignmentHelpersTrait
Open
class TwigXmlFormat extends AbstractTwigFormat
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::setOptionsDefaults
Open
$this
- Exclude checks
Reference to undeclared constant \Phug\Formatter\Format\TwigXmlFormat::SAVE_VALUE
Open
'save_value' => static::SAVE_VALUE,
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\MarkupInterface
Open
protected function isBlockTag(MarkupInterface $element)
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'])) {
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\Element\ExpressionElement
Open
if ($name instanceof ExpressionElement) {
- Exclude checks
Call to method isChecked
from undeclared class \Phug\Formatter\Element\ExpressionElement
Open
$this->formatCode($name->getValue(), $name->isChecked())
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\Element\MarkupElement
Open
protected function formatPairTagChildren(MarkupElement $element)
- Exclude checks
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)
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\Element\AssignmentElement
Open
protected function formatAssignmentElement(AssignmentElement $element)
- Exclude checks
Checking instanceof against undeclared class \Phug\Formatter\Element\TextElement
Open
if ($value instanceof TextElement && $nonEmptyAttribute && (!$value->getValue() || $value->getValue() === '')) {
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::registerHelper
Open
return $this->registerHelper('available_attribute_assignments', $availableAssignments);
- Exclude checks
Parameter $element
has undeclared type \Phug\Formatter\Element\AttributeElement
Open
protected function formatAttributeElement(AttributeElement $element)
- Exclude checks
Call to undeclared method \Phug\Formatter\Format\TwigXmlFormat::pattern
Open
$this->pattern(
- Exclude checks
Call to method hasChildren
from undeclared class \Phug\Formatter\Element\MarkupElement
Open
$element->hasChildren()
- Exclude checks
Call to method getValue
from undeclared class \Phug\Formatter\Element\AbstractValueElement
Open
$value = $value->getValue();
- Exclude checks