File XmlFormat.php
has 448 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Phug\Formatter\Format;
use Closure;
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) ?: [];
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" ?>';
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');
- 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 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');
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')) {
- 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
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) ?: [];
- 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 __construct
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(Formatter $formatter = null)
{
parent::__construct($formatter);
$this
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) {
- 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
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;
- 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
Consider simplifying this complex logical expression. Open
if ($nonEmptyAttribute && (
!$value ||
($value instanceof TextElement && ((string) $value->getValue()) === '') ||
(is_string($value) && in_array(trim($value), ['', '""', "''"], true))
)) {
Avoid too many return
statements within this method. Open
return $this->pattern(
'attribute_pattern',
$this->format($name),
$this->format($value)
);