The method ParseVisitor::visitPropGroup() calls the typical debug function print_r() which is mostly only used during development. Open
. \print_r($property_name, true)
- Read upRead up
- Exclude checks
DevelopmentCodeFragment
Since: 2.3.0
Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.
Example
class SuspectCode {
public function doSomething(array $items)
{
foreach ($items as $i => $item) {
// …
if ('qafoo' == $item) var_dump($i);
// …
}
}
}
Source https://phpmd.org/rules/design.html#developmentcodefragment
File ParseVisitor.php
has 1166 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Parse;
Function addProperty
has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
{
$variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
// If something goes wrong will getting the type of
- 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 addProperty
has 165 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
{
$variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
// If something goes wrong will getting the type of
ParseVisitor
has 44 functions (exceeds 20 allowed). Consider refactoring. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
Method visitClass
has 93 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitClass(Node $node): Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode(
$this->code_base,
Method visitClassConstDecl
has 91 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitClassConstDecl(Node $node): Context
{
$class = $this->getContextClass();
foreach ($node->children as $child_node) {
The class ParseVisitor has an overall complexity of 201 which is very high. The configured complexity threshold is 50. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
- Exclude checks
The class ParseVisitor has 32 public methods. Consider refactoring ParseVisitor to keep number of public methods under 10. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class ParseVisitor has 41 non-getter- and setter-methods. Consider refactoring ParseVisitor to keep number of methods under 25. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
Method addConstant
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function addConstant(
CodeBase $code_base,
Context $context,
int $lineno,
string $name,
Function visitClassConstDecl
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function visitClassConstDecl(Node $node): Context
{
$class = $this->getContextClass();
foreach ($node->children as $child_node) {
- 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 visitDim
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function visitDim(Node $node): Context
{
if (!Config::get_backward_compatibility_checks()) {
return $this->context;
}
- 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 visitCall
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function visitCall(Node $node): Context
{
// If this is a call to a method that indicates that we
// are treating the method in scope as a varargs method,
// then set its optional args to something very high so
- 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 visitMethod
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function visitMethod(Node $node): Context
{
// Bomb out if we're not in a class context
$class = $this->getContextClass();
$context = $this->context;
- 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 visitPropGroup
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitPropGroup(Node $node): Context
{
// Bomb out if we're not in a class context
['props' => $props_node, 'type' => $type_node] = $node->children;
if (!$props_node instanceof Node) {
Method visitDim
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitDim(Node $node): Context
{
if (!Config::get_backward_compatibility_checks()) {
return $this->context;
}
Function visitPropGroup
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function visitPropGroup(Node $node): Context
{
// Bomb out if we're not in a class context
['props' => $props_node, 'type' => $type_node] = $node->children;
if (!$props_node instanceof Node) {
- 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 visitMethod
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitMethod(Node $node): Context
{
// Bomb out if we're not in a class context
$class = $this->getContextClass();
$context = $this->context;
Function addConstant
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function addConstant(
CodeBase $code_base,
Context $context,
int $lineno,
string $name,
- 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 addPromotedConstructorPropertyFromParam
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addPromotedConstructorPropertyFromParam(
Clazz $class,
Method $method,
Parameter $parameter,
Node $parameter_node
Function visitClass
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function visitClass(Node $node): Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode(
$this->code_base,
- 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 visitStaticCall
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function visitStaticCall(Node $node): Context
{
$call = $node->children['class'];
if ($call instanceof Node && $call->kind === \ast\AST_NAME) {
- 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 visitFuncDecl
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitFuncDecl(Node $node): Context
{
$function_name = (string)$node->children['name'];
$context = $this->context;
$code_base = $this->code_base;
Method addConstant
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
int $lineno,
string $name,
$value,
Method addProperty
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
Method visitCall
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitCall(Node $node): Context
{
// If this is a call to a method that indicates that we
// are treating the method in scope as a varargs method,
// then set its optional args to something very high so
Method analyzeDefine
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzeDefine(Node $node): void
{
$args = $node->children['args'];
if (\count($args->children) < 2) {
return;
Method visitConstDecl
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitConstDecl(Node $node): Context
{
foreach ($node->children as $child_node) {
if (!$child_node instanceof Node) {
throw new AssertionError("Expected global constant element to be a Node");
Function visitFuncDecl
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function visitFuncDecl(Node $node): Context
{
$function_name = (string)$node->children['name'];
$context = $this->context;
$code_base = $this->code_base;
- 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
Avoid too many return
statements within this method. Open
return $this->context;
Function addPromotedConstructorPropertyFromParam
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function addPromotedConstructorPropertyFromParam(
Clazz $class,
Method $method,
Parameter $parameter,
Node $parameter_node
- 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 visitConstDecl
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function visitConstDecl(Node $node): Context
{
foreach ($node->children as $child_node) {
if (!$child_node instanceof Node) {
throw new AssertionError("Expected global constant element to be a Node");
- 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
The class ParseVisitor has 1705 lines of code. Current threshold is 1000. Avoid really long classes. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
- Exclude checks
The method visitClass() has 142 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function visitClass(Node $node): Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode(
$this->code_base,
- Exclude checks
The method visitClass() has an NPath complexity of 400. The configured NPath complexity threshold is 200. Open
public function visitClass(Node $node): Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode(
$this->code_base,
- 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 addProperty() has an NPath complexity of 1709696. The configured NPath complexity threshold is 200. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
{
$variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
// If something goes wrong will getting the type of
- 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 visitClassConstDecl() has 108 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function visitClassConstDecl(Node $node): Context
{
$class = $this->getContextClass();
foreach ($node->children as $child_node) {
- Exclude checks
The method addProperty() has 209 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
{
$variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
// If something goes wrong will getting the type of
- Exclude checks
The method addConstant() has 114 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function addConstant(
CodeBase $code_base,
Context $context,
int $lineno,
string $name,
- Exclude checks
The method visitClassConstDecl() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function visitClassConstDecl(Node $node): Context
{
$class = $this->getContextClass();
foreach ($node->children as $child_node) {
- 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
The method visitPropGroup() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function visitPropGroup(Node $node): Context
{
// Bomb out if we're not in a class context
['props' => $props_node, 'type' => $type_node] = $node->children;
if (!$props_node instanceof Node) {
- 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
The method visitDim() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
public function visitDim(Node $node): Context
{
if (!Config::get_backward_compatibility_checks()) {
return $this->context;
}
- 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
The method visitMethod() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function visitMethod(Node $node): Context
{
// Bomb out if we're not in a class context
$class = $this->getContextClass();
$context = $this->context;
- 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
The method visitCall() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function visitCall(Node $node): Context
{
// If this is a call to a method that indicates that we
// are treating the method in scope as a varargs method,
// then set its optional args to something very high so
- 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
The method addProperty() has a Cyclomatic Complexity of 35. The configured cyclomatic complexity threshold is 10. Open
private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
{
$variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
// If something goes wrong will getting the type of
- 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
The method visitClass() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function visitClass(Node $node): Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode(
$this->code_base,
- 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
The class ParseVisitor has a coupling between objects value of 43. Consider to reduce the number of dependencies under 13. Open
class ParseVisitor extends ScopeVisitor
{
/**
* @param Context $context
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = \strrpos($name, '\\');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
public static function checkIsAllowedInConstExpr($n): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
public static function isNonVariableExpr($n): bool
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function checkIsNonVariableExpression($n): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
public static function isConstExpr($n): bool
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}