File ConditionVisitorUtil.php
has 1275 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Analysis;
Function combineTypesAfterWeakEqualityCheck
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
protected function combineTypesAfterWeakEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$old_union_type->hasRealTypeSet()) {
// This is a weak check of equality. We aren't sure of the real 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
Function analyzeBinaryConditionSide
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeBinaryConditionSide(Node $var_node, $expr_node, BinaryCondition $condition): ?Context
{
'@phan-var ConditionVisitorUtil|ConditionVisitorInterface $this';
$kind = $var_node->kind;
if ($kind === ast\AST_VAR || $kind === ast\AST_DIM) {
- 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 updateVariableToBeNotEqual
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
final public function updateVariableToBeNotEqual(
Node $var_node,
$expr,
Context $context = null
): 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 removeTruthyFromVariable
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function removeTruthyFromVariable(Node $var_node, Context $context, bool $suppress_issues, bool $check_empty): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
Function getVariableFromScope
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
final public function getVariableFromScope(Node $var_node, Context $context): ?Variable
{
if ($var_node->kind !== ast\AST_VAR) {
return 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
Function updateVariableToBeCompared
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
final public function updateVariableToBeCompared(
Node $var_node,
$expr,
int $flags
): 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 getVariableFromScope
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
final public function getVariableFromScope(Node $var_node, Context $context): ?Variable
{
if ($var_node->kind !== ast\AST_VAR) {
return null;
}
Method removeLiteralScalarFromVariable
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function removeLiteralScalarFromVariable(
Node $var_node,
Context $context,
$value,
bool $strict_equality
Function getVarNameOfDimNode
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private static function getVarNameOfDimNode($node): ?string
{
// Loop to support getting the var name in is_array($x['field'][0])
while (true) {
if (!($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 combineTypesAfterStrictEqualityCheck
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function combineTypesAfterStrictEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$new_union_type->hasRealTypeSet()) {
return $new_union_type->withRealTypeSet($old_union_type->getRealTypeSet());
- 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 modifyComplexExpression
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected function modifyComplexExpression($node, Closure $type_modification_callback, Context $context, array $args): Context
{
for (;;) {
if (!$node instanceof Node) {
return $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 analyzeClassAssertion
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function analyzeClassAssertion($object_node, $expr_node): ?Context
{
if (!($object_node instanceof Node)) {
return null;
}
Method checkRedundantOrImpossibleTruthyCondition
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function checkRedundantOrImpossibleTruthyCondition($node, Context $context, ?UnionType $type, bool $is_negated): void
{
if ($node instanceof Node) {
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_redundant_condition)) {
Function checkErrorProneTruthyCast
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private function checkErrorProneTruthyCast(Node $node, Context $context, UnionType $union_type): void
{
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_error_prone_truthy)) {
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 modifyComplexExpression
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function modifyComplexExpression($node, Closure $type_modification_callback, Context $context, array $args): Context
{
for (;;) {
if (!$node instanceof Node) {
return $context;
Method updateVariableToBeCompared
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
final public function updateVariableToBeCompared(
Node $var_node,
$expr,
int $flags
): Context {
Method checkErrorProneTruthyCast
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function checkErrorProneTruthyCast(Node $node, Context $context, UnionType $union_type): void
{
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_error_prone_truthy)) {
return;
Method analyzeBinaryConditionSide
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function analyzeBinaryConditionSide(Node $var_node, $expr_node, BinaryCondition $condition): ?Context
{
'@phan-var ConditionVisitorUtil|ConditionVisitorInterface $this';
$kind = $var_node->kind;
if ($kind === ast\AST_VAR || $kind === ast\AST_DIM) {
Method combineTypesAfterWeakEqualityCheck
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function combineTypesAfterWeakEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$old_union_type->hasRealTypeSet()) {
// This is a weak check of equality. We aren't sure of the real types
Method updateDimExpressionWithConditionalFilter
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function updateDimExpressionWithConditionalFilter(
Node $node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
Function updateDimExpressionWithConditionalFilter
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
final protected function updateDimExpressionWithConditionalFilter(
Node $node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
- 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 updateVariableToBeNotIdentical
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
final public function updateVariableToBeNotIdentical(
Node $var_node,
$expr,
Context $context = null
): 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 checkRedundantOrImpossibleTruthyCondition
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function checkRedundantOrImpossibleTruthyCondition($node, Context $context, ?UnionType $type, bool $is_negated): void
{
if ($node instanceof Node) {
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_redundant_condition)) {
- 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 removeFalseyFromVariable
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function removeFalseyFromVariable(Node $var_node, Context $context, bool $suppress_issues): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
Method asTypeSupportingAccess
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function asTypeSupportingAccess(UnionType $type, int $access_type): UnionType
{
$type = $type->asMappedListUnionType(/** @return list<Type> */ static function (Type $type) use ($access_type): array {
if ($access_type === ConditionVisitor::ACCESS_IS_OBJECT) {
if (!$type->isPossiblyObject()) {
Method updateVariableWithNewType
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function updateVariableWithNewType(
Node $var_node,
Context $context,
UnionType $new_union_type,
bool $suppress_issues,
Method updateVariableToBeNotEqual
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
final public function updateVariableToBeNotEqual(
Node $var_node,
$expr,
Context $context = null
): Context {
Method removeTypesNotSupportingAccessFromVariable
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function removeTypesNotSupportingAccessFromVariable(Node $var_node, Context $context, int $access_type): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
Method updateVariableWithConditionalFilter
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
final protected function updateVariableWithConditionalFilter(
Node $var_node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
Function analyzeClassAssertion
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function analyzeClassAssertion($object_node, $expr_node): ?Context
{
if (!($object_node instanceof Node)) {
return 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
Function excludeMatchingTypes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function excludeMatchingTypes(CodeBase $code_base, UnionType $affected_type, UnionType $excluded_type): UnionType
{
if ($affected_type->isEmpty() || $excluded_type->isEmpty()) {
return $affected_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 combineTypesAfterStrictEqualityCheck
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function combineTypesAfterStrictEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$new_union_type->hasRealTypeSet()) {
return $new_union_type->withRealTypeSet($old_union_type->getRealTypeSet());
Function updateVariableWithConditionalFilter
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
final protected function updateVariableWithConditionalFilter(
Node $var_node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
- 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 updateVariableWithNewType
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
final protected function updateVariableWithNewType(
Node $var_node,
Context $context,
UnionType $new_union_type,
bool $suppress_issues,
- 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 updateDimExpressionWithConditionalFilter
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Node $node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
bool $suppress_issues,
Method updateVariableWithConditionalFilter
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Node $var_node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
bool $suppress_issues,
Method updatePropertyExpressionWithConditionalFilter
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Node $node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
bool $suppress_issues
Method updateVariableWithNewType
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Node $var_node,
Context $context,
UnionType $new_union_type,
bool $suppress_issues,
bool $is_weak_type_assertion
Function removeLiteralScalarFromVariable
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
final protected function removeLiteralScalarFromVariable(
Node $var_node,
Context $context,
$value,
bool $strict_equality
- 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 null;
Avoid too many return
statements within this method. Open
return NonZeroIntType::instance($type->isNullable());
Avoid too many return
statements within this method. Open
return $condition->analyzeCall($this, $var_node, $expr_node);
Avoid too many return
statements within this method. Open
return $condition->analyzeVar($this, $var, $expr_node);
Avoid too many return
statements within this method. Open
return $this->context->withScopeVariable(
$variable
);
Avoid too many return
statements within this method. Open
return is_string($var_name) ? $var_name : null;
Avoid too many return
statements within this method. Open
return !$type->containsTruthy();
Avoid too many return
statements within this method. Open
return \get_class($type) === IntType::class;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
static function (UnionType $union_type) use ($cb): bool {
return $union_type->hasPhpdocOrRealTypeMatchingCallback($cb);
Avoid too many return
statements within this method. Open
return $this->removeTrueFromVariable($var_node, $context);
Avoid too many return
statements within this method. Open
return $this->removeNullFromVariable($var_node, $context, false);
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $type;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $this->removeLiteralScalarFromVariable($var_node, $context, $expr, true);
Avoid too many return
statements within this method. Open
return $condition->analyzeComplexCondition($this, $tmp, $expr_node);
Avoid too many return
statements within this method. Open
return $context->withScopeVariable(
$variable
);
Avoid too many return
statements within this method. Open
return [$type->withIsNullable(false)];
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $this->removeFalseFromVariable($var_node, $context);
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return $type;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return !$type->containsFalsey();
Avoid too many return
statements within this method. Open
return [$type->asNonFalseyType()];
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $type->withRealTypeSet(UnionType::typeSetFromString(ConditionVisitor::DEFAULTS_FOR_ACCESS_TYPE[$access_type]));
Avoid too many return
statements within this method. Open
return (new AssignmentVisitor(
$this->code_base,
// We clone the original context to avoid affecting the original context for the elseif.
// AssignmentVisitor modifies the provided context in place.
//
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $context;
Avoid too many return
statements within this method. Open
return $context->getScope()->getVariableByName(
$variable_name
);
Function getTypesFallback
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
final protected function getTypesFallback(Node $var_node, Context $context): ?UnionType
{
if ($var_node->kind !== ast\AST_VAR) {
return 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
Function analyzeBinaryConditionPattern
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function analyzeBinaryConditionPattern($left, $right, BinaryCondition $condition): Context
{
if ($left instanceof Node) {
$result = $this->analyzeBinaryConditionSide($left, $right, $condition);
if ($result !== 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
The method asTypeSupportingAccess() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open
public static function asTypeSupportingAccess(UnionType $type, int $access_type): UnionType
{
$type = $type->asMappedListUnionType(/** @return list<Type> */ static function (Type $type) use ($access_type): array {
if ($access_type === ConditionVisitor::ACCESS_IS_OBJECT) {
if (!$type->isPossiblyObject()) {
- 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 analyzeBinaryConditionSide() has an NPath complexity of 1200. The configured NPath complexity threshold is 200. Open
private function analyzeBinaryConditionSide(Node $var_node, $expr_node, BinaryCondition $condition): ?Context
{
'@phan-var ConditionVisitorUtil|ConditionVisitorInterface $this';
$kind = $var_node->kind;
if ($kind === ast\AST_VAR || $kind === ast\AST_DIM) {
- 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 analyzeClassAssertion() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open
public function analyzeClassAssertion($object_node, $expr_node): ?Context
{
if (!($object_node instanceof Node)) {
return 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 combineTypesAfterWeakEqualityCheck() has an NPath complexity of 568. The configured NPath complexity threshold is 200. Open
protected function combineTypesAfterWeakEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$old_union_type->hasRealTypeSet()) {
// This is a weak check of equality. We aren't sure of the real 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 modifyComplexExpression() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
protected function modifyComplexExpression($node, Closure $type_modification_callback, Context $context, array $args): Context
{
for (;;) {
if (!$node instanceof Node) {
return $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 asTypeSupportingAccess() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function asTypeSupportingAccess(UnionType $type, int $access_type): UnionType
{
$type = $type->asMappedListUnionType(/** @return list<Type> */ static function (Type $type) use ($access_type): array {
if ($access_type === ConditionVisitor::ACCESS_IS_OBJECT) {
if (!$type->isPossiblyObject()) {
- 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 updateDimExpressionWithConditionalFilter() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
final protected function updateDimExpressionWithConditionalFilter(
Node $node,
Context $context,
Closure $should_filter_cb,
Closure $filter_union_type_cb,
- 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 getVariableFromScope() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
final public function getVariableFromScope(Node $var_node, Context $context): ?Variable
{
if ($var_node->kind !== ast\AST_VAR) {
return 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 getVarNameOfDimNode() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private static function getVarNameOfDimNode($node): ?string
{
// Loop to support getting the var name in is_array($x['field'][0])
while (true) {
if (!($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 removeFalseyFromVariable() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
final protected function removeFalseyFromVariable(Node $var_node, Context $context, bool $suppress_issues): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$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 checkErrorProneTruthyCast() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
private function checkErrorProneTruthyCast(Node $node, Context $context, UnionType $union_type): void
{
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_error_prone_truthy)) {
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 analyzeBinaryConditionSide() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
private function analyzeBinaryConditionSide(Node $var_node, $expr_node, BinaryCondition $condition): ?Context
{
'@phan-var ConditionVisitorUtil|ConditionVisitorInterface $this';
$kind = $var_node->kind;
if ($kind === ast\AST_VAR || $kind === ast\AST_DIM) {
- 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 removeTruthyFromVariable() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
final protected function removeTruthyFromVariable(Node $var_node, Context $context, bool $suppress_issues, bool $check_empty): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$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 analyzeClassAssertion() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function analyzeClassAssertion($object_node, $expr_node): ?Context
{
if (!($object_node instanceof Node)) {
return 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 combineTypesAfterWeakEqualityCheck() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
protected function combineTypesAfterWeakEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$old_union_type->hasRealTypeSet()) {
// This is a weak check of equality. We aren't sure of the real 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 method updateVariableToBeCompared() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
final public function updateVariableToBeCompared(
Node $var_node,
$expr,
int $flags
): 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 updateVariableToBeNotEqual() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
final public function updateVariableToBeNotEqual(
Node $var_node,
$expr,
Context $context = null
): 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 checkRedundantOrImpossibleTruthyCondition() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function checkRedundantOrImpossibleTruthyCondition($node, Context $context, ?UnionType $type, bool $is_negated): void
{
if ($node instanceof Node) {
// Here, we only perform the redundant condition checks on whichever ran first, to avoid warning about both impossible and redundant conditions
if (isset($node->did_check_redundant_condition)) {
- 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 removeLiteralScalarFromVariable() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
final protected function removeLiteralScalarFromVariable(
Node $var_node,
Context $context,
$value,
bool $strict_equality
- 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 combineTypesAfterStrictEqualityCheck() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
protected function combineTypesAfterStrictEqualityCheck(UnionType $old_union_type, UnionType $new_union_type): UnionType
{
// TODO: Be more precise about these checks - e.g. forbid anything such as stdClass == false in the new type
if (!$new_union_type->hasRealTypeSet()) {
return $new_union_type->withRealTypeSet($old_union_type->getRealTypeSet());
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
final protected function removeFalseFromVariable(Node $var_node, Context $context): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
- 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 143.
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
final protected function removeTrueFromVariable(Node $var_node, Context $context): Context
{
return $this->updateVariableWithConditionalFilter(
$var_node,
$context,
- 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 143.
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
final public function updateVariableToBeIdentical(
Node $var_node,
$expr,
Context $context = null
): Context {
- 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 115.
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
final public function updateVariableToBeEqual(
Node $var_node,
$expr,
Context $context = null
): Context {
- 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 115.
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
Avoid variables with short names like $cb. Configured minimum length is 3. Open
$cb = static function (Type $type) use ($value): 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;
}
}
}