File ContextNode.php
has 1912 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\AST;
Function getProperty
has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring. Open
public function getProperty(
bool $is_static,
bool $is_known_assignment = false
): Property {
$node = $this->node;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getProperty
has 213 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getProperty(
bool $is_static,
bool $is_known_assignment = false
): Property {
$node = $this->node;
ContextNode
has 47 functions (exceeds 20 allowed). Consider refactoring. Open
class ContextNode
{
/** @var CodeBase The code base within which we're operating */
private $code_base;
Function getMethod
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring. Open
public function getMethod(
$method_name,
bool $is_static,
bool $is_direct = false,
bool $is_new_expression = false
- 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 getClassList
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
public function getClassList(
bool $ignore_missing_classes = false,
int $expected_type_categories = self::CLASS_LIST_ACCEPT_ANY,
string $custom_issue_type = null,
bool $warn_if_wrong_type = true
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getMethod
has 156 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getMethod(
$method_name,
bool $is_static,
bool $is_direct = false,
bool $is_new_expression = false
Function getConst
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public function getConst(): GlobalConstant
{
$node = $this->node;
if (!$node instanceof Node) {
throw new AssertionError('$node must be a node');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function analyzeBackwardCompatibility
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public function analyzeBackwardCompatibility(): void
{
if (!Config::get_backward_compatibility_checks()) {
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
Function getEquivalentPHPValueForNode
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public function getEquivalentPHPValueForNode($node, int $flags)
{
if (!($node instanceof Node)) {
return $node;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getEquivalentPHPValueForNode
has 109 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getEquivalentPHPValueForNode($node, int $flags)
{
if (!($node instanceof Node)) {
return $node;
}
Function getFunction
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function getFunction(
string $function_name,
bool $is_function_declaration = false,
bool $return_placeholder_for_undefined = false
): FunctionInterface {
- 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 analyzeBackwardCompatibility
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function analyzeBackwardCompatibility(): void
{
if (!Config::get_backward_compatibility_checks()) {
return;
}
Method getClassConst
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getClassConst(): ClassConstant
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
Method getConst
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getConst(): GlobalConstant
{
$node = $this->node;
if (!$node instanceof Node) {
throw new AssertionError('$node must be a node');
The class ContextNode has an overall complexity of 396 which is very high. The configured complexity threshold is 50. Open
class ContextNode
{
/** @var CodeBase The code base within which we're operating */
private $code_base;
- Exclude checks
Method handleTraitPrecedence
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleTraitPrecedence(array $adaptations_map, Node $adaptation_node): void
{
// TODO: Should also verify that the original method exists, in a future PR?
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_node instanceof Node) {
Function getEquivalentPHPArrayElements
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
private function getEquivalentPHPArrayElements(Node $node, int $flags): ?array
{
$elements = [];
foreach ($node->children as $child_node) {
if (!($child_node instanceof Node)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method handleTraitAlias
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleTraitAlias(array $adaptations_map, Node $adaptation_node): void
{
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_node instanceof Node) {
throw new AssertionError("Expected node for trait alias");
Consider simplifying this complex logical expression. Open
if ($union_type->isDefinitelyUndefined()
|| (!$union_type->isEmpty()
&& $union_type->isNativeType()
&& !$union_type->hasTypeMatchingCallback(static function (Type $type): bool {
return !$type->isNullableLabeled() && ($type instanceof MixedType || $type instanceof ObjectType);
Method getClassList
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getClassList(
bool $ignore_missing_classes = false,
int $expected_type_categories = self::CLASS_LIST_ACCEPT_ANY,
string $custom_issue_type = null,
bool $warn_if_wrong_type = true
Method getOrCreateProperty
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getOrCreateProperty(
string $property_name,
bool $is_static
): Property {
Method getFunction
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFunction(
string $function_name,
bool $is_function_declaration = false,
bool $return_placeholder_for_undefined = false
): FunctionInterface {
Method getClassListInner
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getClassListInner(bool $ignore_missing_classes): array
{
$node = $this->node;
if (!($node instanceof Node)) {
if (\is_string($node)) {
Consider simplifying this complex logical expression. Open
if ((
(
$lnode->children['prop'] instanceof Node
&& $lnode->children['prop']->kind === ast\AST_VAR
)
Function getClassConst
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function getClassConst(): ClassConstant
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function handleTraitPrecedence
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function handleTraitPrecedence(array $adaptations_map, Node $adaptation_node): void
{
// TODO: Should also verify that the original method exists, in a future PR?
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_node instanceof Node) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getVariableName
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getVariableName(): string
{
if (!($this->node instanceof Node)) {
return (string)$this->node;
}
Method getFunctionFromNode
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFunctionFromNode(bool $return_placeholder_for_undefined = false): iterable
{
$expression = $this->node;
if (!($expression instanceof Node)) {
if (!\is_string($expression)) {
Method getFunctionLikeFromDynamicExpression
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getFunctionLikeFromDynamicExpression(): \Generator
{
$code_base = $this->code_base;
$context = $this->context;
$expression = $this->node;
Method getVariableStrict
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getVariableStrict(): Variable
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
Function getVariableName
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getVariableName(): string
{
if (!($this->node instanceof Node)) {
return (string)$this->node;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getVariable
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getVariable(): Variable
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
Method resolveClassNameInContext
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function resolveClassNameInContext(): ?FullyQualifiedClassName
{
// A function argument to resolve into an FQSEN
$arg = $this->node;
Method getEquivalentPHPArrayElements
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getEquivalentPHPArrayElements(Node $node, int $flags): ?array
{
$elements = [];
foreach ($node->children as $child_node) {
if (!($child_node instanceof Node)) {
Method getOrCreateVariableForReferenceParameter
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getOrCreateVariableForReferenceParameter(Parameter $parameter, ?Parameter $real_parameter): Variable
{
// Return the original variable if it existed
try {
$variable = $this->getVariable();
Function getOrCreateProperty
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getOrCreateProperty(
string $property_name,
bool $is_static
): Property {
- 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 getClassListInner
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getClassListInner(bool $ignore_missing_classes): array
{
$node = $this->node;
if (!($node instanceof Node)) {
if (\is_string($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 getTraitAdaptationsMap
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getTraitAdaptationsMap(array $trait_fqsen_list): array
{
if (!($this->node instanceof Node)) {
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
Function getVariableStrict
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getVariableStrict(): Variable
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getFunctionLikeFromDynamicExpression
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function getFunctionLikeFromDynamicExpression(): \Generator
{
$code_base = $this->code_base;
$context = $this->context;
$expression = $this->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
Avoid deeply nested control flow statements. Open
if ($union_type->isType(NullType::instance(false))) {
$custom_issue_type = Issue::TypeExpectedObjectPropAccessButGotNull;
}
Function getOrCreateVariableForReferenceParameter
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getOrCreateVariableForReferenceParameter(Parameter $parameter, ?Parameter $real_parameter): Variable
{
// Return the original variable if it existed
try {
$variable = $this->getVariable();
- 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 getFunctionFromNode
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getFunctionFromNode(bool $return_placeholder_for_undefined = false): iterable
{
$expression = $this->node;
if (!($expression instanceof Node)) {
if (!\is_string($expression)) {
- 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 resolveClassNameInContext
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function resolveClassNameInContext(): ?FullyQualifiedClassName
{
// A function argument to resolve into an FQSEN
$arg = $this->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 handleTraitAlias
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function handleTraitAlias(array $adaptations_map, Node $adaptation_node): void
{
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_node instanceof Node) {
throw new AssertionError("Expected node for trait alias");
- 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 $new_node;
Avoid too many return
statements within this method. Open
return UnionTypeVisitor::unionTypeFromNode($this->code_base, $this->context, $node, false)->asSingleScalarValueOrNull() ?? $node;
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $raw_function_name($arg_value);
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $this->getValueForCall($node, $flags);
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $this->getValueForMagicConstByNode($node);
Avoid too many return
statements within this method. Open
return (string)$name_node;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $this->returnStubOrThrowUndeclaredFunctionIssueException(
$function_fqsen,
$not_fully_qualified,
$not_fully_qualified ? FullyQualifiedFunctionName::make($namespace, $function_name) : $function_fqsen,
$return_placeholder_for_undefined
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return [$union_type, $class_list];
Avoid too many return
statements within this method. Open
return $code_base->getFunctionByFQSEN($function_fqsen);
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $value;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $class_list;
Avoid too many return
statements within this method. Open
return $this->getValueForEmptyCheck($node, $flags);
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $this->getValueForIssetCheck($node, $flags);
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $code_base->getFunctionByFQSEN($function_fqsen);
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $this->getValueForUnaryOp($node, $flags);
Avoid too many return
statements within this method. Open
return $new_node;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return (string)$name_node_type->asSingleScalarValueOrNull();
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return $code_base->getFunctionByFQSEN($function_fqsen);
Avoid too many return
statements within this method. Open
return $this->returnStubOrThrowUndeclaredFunctionIssueException($function_fqsen, false, null, $return_placeholder_for_undefined);
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $node;
Avoid too many return
statements within this method. Open
return $this->getValueForBinaryOp($node, $flags);
Avoid too many return
statements within this method. Open
return $node;
The method getConst() has 107 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getConst(): GlobalConstant
{
$node = $this->node;
if (!$node instanceof Node) {
throw new AssertionError('$node must be a node');
- Exclude checks
The method getFunction() has an NPath complexity of 210. The configured NPath complexity threshold is 200. Open
public function getFunction(
string $function_name,
bool $is_function_declaration = false,
bool $return_placeholder_for_undefined = false
): FunctionInterface {
- 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 handleTraitPrecedence() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open
private function handleTraitPrecedence(array $adaptations_map, Node $adaptation_node): void
{
// TODO: Should also verify that the original method exists, in a future PR?
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_node instanceof Node) {
- 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 getVariableName() has an NPath complexity of 360. The configured NPath complexity threshold is 200. Open
public function getVariableName(): string
{
if (!($this->node instanceof Node)) {
return (string)$this->node;
}
- 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 getProperty() has an NPath complexity of 83187500. The configured NPath complexity threshold is 200. Open
public function getProperty(
bool $is_static,
bool $is_known_assignment = false
): Property {
$node = $this->node;
- 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 getClassConst() has 106 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getClassConst(): ClassConstant
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
- Exclude checks
The method getEquivalentPHPValueForNode() has an NPath complexity of 248. The configured NPath complexity threshold is 200. Open
public function getEquivalentPHPValueForNode($node, int $flags)
{
if (!($node instanceof Node)) {
return $node;
}
- 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 getConst() has an NPath complexity of 6720. The configured NPath complexity threshold is 200. Open
public function getConst(): GlobalConstant
{
$node = $this->node;
if (!$node instanceof Node) {
throw new AssertionError('$node must be a node');
- 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 analyzeBackwardCompatibility() has an NPath complexity of 483840. The configured NPath complexity threshold is 200. Open
public function analyzeBackwardCompatibility(): void
{
if (!Config::get_backward_compatibility_checks()) {
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 analyzeBackwardCompatibility() has 127 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function analyzeBackwardCompatibility(): void
{
if (!Config::get_backward_compatibility_checks()) {
return;
}
- Exclude checks
The method getEquivalentPHPValueForNode() has 123 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getEquivalentPHPValueForNode($node, int $flags)
{
if (!($node instanceof Node)) {
return $node;
}
- Exclude checks
The method getOrCreateProperty() has an NPath complexity of 200. The configured NPath complexity threshold is 200. Open
public function getOrCreateProperty(
string $property_name,
bool $is_static
): Property {
- 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 getProperty() has 267 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getProperty(
bool $is_static,
bool $is_known_assignment = false
): Property {
$node = $this->node;
- Exclude checks
The method getClassConst() has an NPath complexity of 312. The configured NPath complexity threshold is 200. Open
public function getClassConst(): ClassConstant
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a node');
- 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 class ContextNode has 2615 lines of code. Current threshold is 1000. Avoid really long classes. Open
class ContextNode
{
/** @var CodeBase The code base within which we're operating */
private $code_base;
- Exclude checks
The method getMethod() has an NPath complexity of 909312. The configured NPath complexity threshold is 200. Open
public function getMethod(
$method_name,
bool $is_static,
bool $is_direct = false,
bool $is_new_expression = false
- 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 getMethod() has 189 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getMethod(
$method_name,
bool $is_static,
bool $is_direct = false,
bool $is_new_expression = false
- Exclude checks
The method getEquivalentPHPValueForNode() has a Cyclomatic Complexity of 35. The configured cyclomatic complexity threshold is 10. Open
public function getEquivalentPHPValueForNode($node, int $flags)
{
if (!($node instanceof Node)) {
return $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 getFunction() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function getFunction(
string $function_name,
bool $is_function_declaration = false,
bool $return_placeholder_for_undefined = false
): FunctionInterface {
- 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 handleTraitPrecedence() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private function handleTraitPrecedence(array $adaptations_map, Node $adaptation_node): void
{
// TODO: Should also verify that the original method exists, in a future PR?
$trait_method_node = $adaptation_node->children['method'];
if (!$trait_method_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 getOrCreateProperty() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function getOrCreateProperty(
string $property_name,
bool $is_static
): Property {
- 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 analyzeBackwardCompatibility() has a Cyclomatic Complexity of 33. The configured cyclomatic complexity threshold is 10. Open
public function analyzeBackwardCompatibility(): void
{
if (!Config::get_backward_compatibility_checks()) {
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 getMethod() has a Cyclomatic Complexity of 40. The configured cyclomatic complexity threshold is 10. Open
public function getMethod(
$method_name,
bool $is_static,
bool $is_direct = false,
bool $is_new_expression = false
- 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 getProperty() has a Cyclomatic Complexity of 45. The configured cyclomatic complexity threshold is 10. Open
public function getProperty(
bool $is_static,
bool $is_known_assignment = false
): Property {
$node = $this->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 getClassConst() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function getClassConst(): ClassConstant
{
$node = $this->node;
if (!($node instanceof Node)) {
throw new AssertionError('$this->node must be a 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 getClassList() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10. Open
public function getClassList(
bool $ignore_missing_classes = false,
int $expected_type_categories = self::CLASS_LIST_ACCEPT_ANY,
string $custom_issue_type = null,
bool $warn_if_wrong_type = true
- 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 getClassListInner() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function getClassListInner(bool $ignore_missing_classes): array
{
$node = $this->node;
if (!($node instanceof Node)) {
if (\is_string($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 getConst() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
public function getConst(): GlobalConstant
{
$node = $this->node;
if (!$node instanceof Node) {
throw new AssertionError('$node must be a 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 getVariableName() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function getVariableName(): string
{
if (!($this->node instanceof Node)) {
return (string)$this->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 class ContextNode has a coupling between objects value of 51. Consider to reduce the number of dependencies under 13. Open
class ContextNode
{
/** @var CodeBase The code base within which we're operating */
private $code_base;
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid using empty try-catch blocks in getMethod. Open
} catch (RecursionDepthException $_) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (!$this->context->getScope()->hasVariableWithName($variable_name)) {
if (Variable::isHardcodedVariableInScopeWithName($variable_name, $this->context->isInGlobalScope())) {
// We return a clone of the global or superglobal variable
// that can't be used to influence the type of that superglobal in other files.
return new Variable(
- 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 121.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (!$scope->hasVariableWithName($variable_name)) {
if (Variable::isHardcodedVariableInScopeWithName($variable_name, $this->context->isInGlobalScope())) {
// We return a clone of the global or superglobal variable
// that can't be used to influence the type of that superglobal in other files.
return new Variable(
- 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 121.
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 $e. Configured minimum length is 3. Open
private function handleErrorInOperation(Node $node, Error $e): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}