File AssignmentVisitor.php
has 1400 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Analysis;
Function analyzeShapedArrayAssignment
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeShapedArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$fallback_element_type = null;
/** @suppress PhanAccessMethodInternal */
- 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 visitVar
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
public function visitVar(Node $node): Context
{
try {
$variable_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 analyzeGenericArrayAssignment
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeGenericArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$right_type = $this->right_type;
if ($right_type->isEmpty()) {
- 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 analyzePropAssignment
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
private function analyzePropAssignment(Clazz $clazz, Property $property, Node $node): Context
{
if ($property->isReadOnly()) {
$this->analyzeAssignmentToReadOnlyProperty($property, $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
AssignmentVisitor
has 36 functions (exceeds 20 allowed). Consider refactoring. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
Method visitVar
has 110 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitVar(Node $node): Context
{
try {
$variable_name = (new ContextNode(
$this->code_base,
Function visitDim
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function visitDim(Node $node): Context
{
$expr_node = $node->children['expr'];
if (!($expr_node instanceof Node)) {
$this->emitIssue(
- 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 visitProp
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function visitProp(Node $node): Context
{
// Get class list first, warn if the class list is invalid.
try {
$class_list = (new ContextNode(
- 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 analyzeGenericArrayAssignment
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzeGenericArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$right_type = $this->right_type;
if ($right_type->isEmpty()) {
Method visitProp
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitProp(Node $node): Context
{
// Get class list first, warn if the class list is invalid.
try {
$class_list = (new ContextNode(
The class AssignmentVisitor has 32 non-getter- and setter-methods. Consider refactoring AssignmentVisitor to keep number of methods under 25. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
- 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
The class AssignmentVisitor has 14 public methods. Consider refactoring AssignmentVisitor to keep number of public methods under 10. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
- 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 AssignmentVisitor has an overall complexity of 293 which is very high. The configured complexity threshold is 50. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
- Exclude checks
Method analyzeShapedArrayAssignment
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzeShapedArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$fallback_element_type = null;
/** @suppress PhanAccessMethodInternal */
Method visitDim
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitDim(Node $node): Context
{
$expr_node = $node->children['expr'];
if (!($expr_node instanceof Node)) {
$this->emitIssue(
Function computeTypeSetOfMergedArrayShapeTypes
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private static function computeTypeSetOfMergedArrayShapeTypes(array $old_type_set, array $new_type_set, int $dim_depth, bool $is_real): array
{
if ($is_real) {
if (!$old_type_set || !$new_type_set) {
return [];
- 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 analyzePropAssignment
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzePropAssignment(Clazz $clazz, Property $property, Node $node): Context
{
if ($property->isReadOnly()) {
$this->analyzeAssignmentToReadOnlyProperty($property, $node);
}
Function typeCheckDimAssignment
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function typeCheckDimAssignment(UnionType $assign_type, Node $node): UnionType
{
static $int_or_string_type = null;
static $string_array_type = null;
static $simple_xml_element_type = null;
- 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 typeCheckDimAssignment
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function typeCheckDimAssignment(UnionType $assign_type, Node $node): UnionType
{
static $int_or_string_type = null;
static $string_array_type = null;
static $simple_xml_element_type = null;
Function addTypesToProperty
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function addTypesToProperty(Property $property, Node $node): void
{
if ($property->getRealUnionType()->isEmpty() && $property->getPHPDocUnionType()->isEmpty()) {
$property->setUnionType(
$this->right_type
- 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 computeTypeSetOfMergedArrayShapeTypes
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function computeTypeSetOfMergedArrayShapeTypes(array $old_type_set, array $new_type_set, int $dim_depth, bool $is_real): array
{
if ($is_real) {
if (!$old_type_set || !$new_type_set) {
return [];
Method visitStaticProp
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function visitStaticProp(Node $node): Context
{
$property_name = $node->children['prop'];
// Things like self::${$x}
Function addTypesToPropertyStandalone
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function addTypesToPropertyStandalone(
CodeBase $code_base,
Context $context,
Property $property,
UnionType $new_types
- 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 normalizeListTypesInDimAssignment
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function normalizeListTypesInDimAssignment(UnionType $assign_type, UnionType $right_type): UnionType
{
// Offsets of $can_cast:
// 0. lazily computed: True if list types should be kept as-is.
// 1. lazily computed: Should this cast from a regular array to an associative array?
Method analyzeValueNodeOfShapedArray
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzeValueNodeOfShapedArray(
UnionType $element_type,
$value_node
): void {
if (!$value_node instanceof Node) {
Method addTypesToProperty
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addTypesToProperty(Property $property, Node $node): void
{
if ($property->getRealUnionType()->isEmpty() && $property->getPHPDocUnionType()->isEmpty()) {
$property->setUnionType(
$this->right_type
Method analyzeSetUnionTypePassByRef
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function analyzeSetUnionTypePassByRef(
CodeBase $code_base,
Context $context,
PassByReferenceVariable $reference_element,
UnionType $new_type,
Method emitTypeMismatchPropertyIssue
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function emitTypeMismatchPropertyIssue(
Node $node,
Property $property,
UnionType $resolved_right_type,
UnionType $warn_type,
Function normalizeListTypesInDimAssignment
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function normalizeListTypesInDimAssignment(UnionType $assign_type, UnionType $right_type): UnionType
{
// Offsets of $can_cast:
// 0. lazily computed: True if list types should be kept as-is.
// 1. lazily computed: Should this cast from a regular array to an associative array?
- 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 analyzeSetUnionTypePassByRef
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function analyzeSetUnionTypePassByRef(
CodeBase $code_base,
Context $context,
PassByReferenceVariable $reference_element,
UnionType $new_type,
- 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 checkAssignmentToFunctionResult
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function checkAssignmentToFunctionResult(Node $node, iterable $function_list_generator): void
{
try {
foreach ($function_list_generator as $function) {
if ($function->returnsRef()) {
- 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 addTypesToPropertyStandalone
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function addTypesToPropertyStandalone(
CodeBase $code_base,
Context $context,
Property $property,
UnionType $new_types
Method analyzePropertyAssignmentStrict
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzePropertyAssignmentStrict(Property $property, UnionType $assignment_type, Node $node): void
{
$type_set = $assignment_type->getTypeSet();
if (\count($type_set) < 2) {
throw new AssertionError('Expected to have at least two types when checking if types match in strict mode');
Function visitStaticProp
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function visitStaticProp(Node $node): Context
{
$property_name = $node->children['prop'];
// Things like self::${$x}
- 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 analyzePropertyAssignmentStrict
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function analyzePropertyAssignmentStrict(Property $property, UnionType $assignment_type, Node $node): void
{
$type_set = $assignment_type->getTypeSet();
if (\count($type_set) < 2) {
throw new AssertionError('Expected to have at least two types when checking if types match in strict mode');
- 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 analyzeValueNodeOfShapedArray
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeValueNodeOfShapedArray(
UnionType $element_type,
$value_node
): void {
if (!$value_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
Function handleThisPropertyAssignmentInLocalScopeByName
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function handleThisPropertyAssignmentInLocalScopeByName(Node $node, string $prop_name): void
{
if ($this->dim_depth === 0) {
$new_type = $this->right_type;
} else {
- 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 6 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
Node $assignment_node,
UnionType $right_type,
int $dim_depth = 0,
Method analyzeSetUnionTypeInContext
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
TypedElementInterface $element,
UnionType $element_type,
$node
Method emitTypeMismatchPropertyIssue
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Node $node,
Property $property,
UnionType $resolved_right_type,
UnionType $warn_type,
UnionType $property_union_type
Method analyzeSetUnionTypePassByRef
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
PassByReferenceVariable $reference_element,
UnionType $new_type,
$node
Function visitMethodCall
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function visitMethodCall(Node $node): Context
{
if ($this->dim_depth >= 2) {
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 analyzeAssignmentToReadOnlyProperty
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeAssignmentToReadOnlyProperty(Property $property, Node $node): void
{
$is_from_phpdoc = $property->isFromPHPDoc();
$context = $property->getContext();
if (!$is_from_phpdoc && $this->context->isInFunctionLikeScope()) {
- 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 false;
Avoid too many return
statements within this method. Open
return $type_set;
Avoid too many return
statements within this method. Open
return $right_type;
Avoid too many return
statements within this method. Open
return $this->context;
Avoid too many return
statements within this method. Open
return UnionType::of($new_type_set, $new_real_type_set);
Avoid too many return
statements within this method. Open
return $this->context;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $this->context;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $right_type;
Avoid too many return
statements within this method. Open
return $this->context;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $this->context;
Avoid too many return
statements within this method. Open
return $this->context;
Function checkMismatchArrayDestructuringKey
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function checkMismatchArrayDestructuringKey($expect_int_keys_lineno, $expect_string_keys_lineno): void
{
if ($expect_int_keys_lineno !== false || $expect_string_keys_lineno !== false) {
$right_hand_key_type = GenericArrayType::keyTypeFromUnionTypeKeys($this->right_type);
if ($expect_int_keys_lineno !== false && ($right_hand_key_type & GenericArrayType::KEY_INT) === 0) {
- 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 method analyzeShapedArrayAssignment() has an NPath complexity of 626. The configured NPath complexity threshold is 200. Open
private function analyzeShapedArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$fallback_element_type = null;
/** @suppress PhanAccessMethodInternal */
- 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 analyzeGenericArrayAssignment() has 116 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function analyzeGenericArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$right_type = $this->right_type;
if ($right_type->isEmpty()) {
- Exclude checks
The method computeTypeSetOfMergedArrayShapeTypes() has an NPath complexity of 576. The configured NPath complexity threshold is 200. Open
private static function computeTypeSetOfMergedArrayShapeTypes(array $old_type_set, array $new_type_set, int $dim_depth, bool $is_real): array
{
if ($is_real) {
if (!$old_type_set || !$new_type_set) {
return [];
- 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 addTypesToProperty() has an NPath complexity of 444. The configured NPath complexity threshold is 200. Open
private function addTypesToProperty(Property $property, Node $node): void
{
if ($property->getRealUnionType()->isEmpty() && $property->getPHPDocUnionType()->isEmpty()) {
$property->setUnionType(
$this->right_type
- 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 visitProp() has 108 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function visitProp(Node $node): Context
{
// Get class list first, warn if the class list is invalid.
try {
$class_list = (new ContextNode(
- Exclude checks
The class AssignmentVisitor has 1924 lines of code. Current threshold is 1000. Avoid really long classes. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
- Exclude checks
The method visitVar() has an NPath complexity of 5472. The configured NPath complexity threshold is 200. Open
public function visitVar(Node $node): Context
{
try {
$variable_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 analyzeGenericArrayAssignment() has an NPath complexity of 363. The configured NPath complexity threshold is 200. Open
private function analyzeGenericArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$right_type = $this->right_type;
if ($right_type->isEmpty()) {
- 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 typeCheckDimAssignment() has an NPath complexity of 420. The configured NPath complexity threshold is 200. Open
public function typeCheckDimAssignment(UnionType $assign_type, Node $node): UnionType
{
static $int_or_string_type = null;
static $string_array_type = null;
static $simple_xml_element_type = null;
- 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 analyzeShapedArrayAssignment() has 101 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function analyzeShapedArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$fallback_element_type = null;
/** @suppress PhanAccessMethodInternal */
- Exclude checks
The method addTypesToPropertyStandalone() has an NPath complexity of 222. The configured NPath complexity threshold is 200. Open
public static function addTypesToPropertyStandalone(
CodeBase $code_base,
Context $context,
Property $property,
UnionType $new_types
- 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 visitVar() has 144 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function visitVar(Node $node): Context
{
try {
$variable_name = (new ContextNode(
$this->code_base,
- Exclude checks
The method analyzePropAssignment() has 103 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function analyzePropAssignment(Clazz $clazz, Property $property, Node $node): Context
{
if ($property->isReadOnly()) {
$this->analyzeAssignmentToReadOnlyProperty($property, $node);
}
- Exclude checks
The method visitDim() has an NPath complexity of 432. The configured NPath complexity threshold is 200. Open
public function visitDim(Node $node): Context
{
$expr_node = $node->children['expr'];
if (!($expr_node instanceof Node)) {
$this->emitIssue(
- 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 visitProp() has an NPath complexity of 5824. The configured NPath complexity threshold is 200. Open
public function visitProp(Node $node): Context
{
// Get class list first, warn if the class list is invalid.
try {
$class_list = (new ContextNode(
- 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 visitDim() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function visitDim(Node $node): Context
{
$expr_node = $node->children['expr'];
if (!($expr_node instanceof Node)) {
$this->emitIssue(
- 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 analyzePropertyAssignmentStrict() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private function analyzePropertyAssignmentStrict(Property $property, UnionType $assignment_type, Node $node): void
{
$type_set = $assignment_type->getTypeSet();
if (\count($type_set) < 2) {
throw new AssertionError('Expected to have at least two types when checking if types match in strict mode');
- 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 visitVar() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10. Open
public function visitVar(Node $node): Context
{
try {
$variable_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 method normalizeListTypesInDimAssignment() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
private static function normalizeListTypesInDimAssignment(UnionType $assign_type, UnionType $right_type): UnionType
{
// Offsets of $can_cast:
// 0. lazily computed: True if list types should be kept as-is.
// 1. lazily computed: Should this cast from a regular array to an associative array?
- 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 visitProp() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function visitProp(Node $node): Context
{
// Get class list first, warn if the class list is invalid.
try {
$class_list = (new ContextNode(
- 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 analyzeGenericArrayAssignment() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
private function analyzeGenericArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$right_type = $this->right_type;
if ($right_type->isEmpty()) {
- 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 analyzeSetUnionTypePassByRef() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private static function analyzeSetUnionTypePassByRef(
CodeBase $code_base,
Context $context,
PassByReferenceVariable $reference_element,
UnionType $new_type,
- 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 addTypesToProperty() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
private function addTypesToProperty(Property $property, Node $node): void
{
if ($property->getRealUnionType()->isEmpty() && $property->getPHPDocUnionType()->isEmpty()) {
$property->setUnionType(
$this->right_type
- 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 typeCheckDimAssignment() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function typeCheckDimAssignment(UnionType $assign_type, Node $node): UnionType
{
static $int_or_string_type = null;
static $string_array_type = null;
static $simple_xml_element_type = null;
- 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 analyzeShapedArrayAssignment() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
private function analyzeShapedArrayAssignment(Node $node): void
{
// Figure out the type of elements in the list
$fallback_element_type = null;
/** @suppress PhanAccessMethodInternal */
- 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 analyzePropAssignment() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10. Open
private function analyzePropAssignment(Clazz $clazz, Property $property, Node $node): Context
{
if ($property->isReadOnly()) {
$this->analyzeAssignmentToReadOnlyProperty($property, $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 computeTypeSetOfMergedArrayShapeTypes() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
private static function computeTypeSetOfMergedArrayShapeTypes(array $old_type_set, array $new_type_set, int $dim_depth, bool $is_real): array
{
if ($is_real) {
if (!$old_type_set || !$new_type_set) {
return [];
- 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 addTypesToPropertyStandalone() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function addTypesToPropertyStandalone(
CodeBase $code_base,
Context $context,
Property $property,
UnionType $new_types
- 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 AssignmentVisitor has a coupling between objects value of 40. Consider to reduce the number of dependencies under 13. Open
class AssignmentVisitor extends AnalysisVisitor
{
/**
* @var UnionType
* The type of the element on the right side of the assignment
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
$result = ($can_cast[0] = ($can_cast[0] ?? $assign_type->hasTypeMatchingCallback(static function (Type $other_type): bool {
if (!$other_type instanceof ArrayType) {
return false;
}
if ($other_type instanceof ListType) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 103.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
$result = ($can_cast[1] = ($can_cast[1] ?? $assign_type->hasTypeMatchingCallback(static function (Type $other_type): bool {
if (!$other_type instanceof ArrayType) {
return false;
}
if ($other_type instanceof AssociativeArrayType) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 103.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76