File BlockExitStatusChecker.php
has 487 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Analysis;
BlockExitStatusChecker
has 43 functions (exceeds 20 allowed). Consider refactoring. Open
final class BlockExitStatusChecker extends KindVisitorImplementation
{
// These should be at most 1 << 31, in order to work in 32-bit php.
// NOTE: Any exit status must be a combination of at least one of these bits
// E.g. if STATUS_PROCEED is mixed with STATUS_RETURN, it would mean it is possible both to go to completion or return.
The class BlockExitStatusChecker has 41 non-getter- and setter-methods. Consider refactoring BlockExitStatusChecker to keep number of methods under 25. Open
final class BlockExitStatusChecker extends KindVisitorImplementation
{
// These should be at most 1 << 31, in order to work in 32-bit php.
// NOTE: Any exit status must be a combination of at least one of these bits
// E.g. if STATUS_PROCEED is mixed with STATUS_RETURN, it would mean it is possible both to go to completion or return.
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
The class BlockExitStatusChecker has an overall complexity of 115 which is very high. The configured complexity threshold is 50. Open
final class BlockExitStatusChecker extends KindVisitorImplementation
{
// These should be at most 1 << 31, in order to work in 32-bit php.
// NOTE: Any exit status must be a combination of at least one of these bits
// E.g. if STATUS_PROCEED is mixed with STATUS_RETURN, it would mean it is possible both to go to completion or return.
- Exclude checks
The class BlockExitStatusChecker has 29 public methods. Consider refactoring BlockExitStatusChecker to keep number of public methods under 10. Open
final class BlockExitStatusChecker extends KindVisitorImplementation
{
// These should be at most 1 << 31, in order to work in 32-bit php.
// NOTE: Any exit status must be a combination of at least one of these bits
// E.g. if STATUS_PROCEED is mixed with STATUS_RETURN, it would mean it is possible both to go to completion or return.
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
Function computeStatusOfCall
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function computeStatusOfCall(Node $node): int
{
$expression = $node->children['expr'];
if ($expression instanceof Node) {
if ($expression->kind !== \ast\AST_NAME) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function computeStatusOfBlock
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function computeStatusOfBlock(array $block): int
{
$maybe_status = 0;
foreach ($block as $child) {
if ($child === 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 computeStatusOfSwitchList
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function computeStatusOfSwitchList(Node $node): int
{
$switch_stmt_case_nodes = $node->children ?? [];
if (\count($switch_stmt_case_nodes) === 0) {
return self::STATUS_PROCEED;
- 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 self::STATUS_PROCEED; // Assume this is a warning or notice?
Avoid too many return
statements within this method. Open
return self::STATUS_PROCEED;
Avoid too many return
statements within this method. Open
return self::computeTriggerErrorStatusCodeForConstant($node->children['args']->children[1] ?? null);
Avoid too many return
statements within this method. Open
return self::STATUS_THROW;
Function computeStatusOfIf
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function computeStatusOfIf(Node $node): int
{
$has_if_elems_for_all_cases = false;
$combined_statuses = 0;
foreach ($node->children as $child_node) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function computeMatchArmStatus
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function computeMatchArmStatus(Node $node): int
{
['cond' => $cond, 'expr' => $expr] = $node->children;
$cond_status = 0;
foreach ($cond->children ?? [] as $cond_expr) {
- 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 computeStatusOfTry
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function computeStatusOfTry(Node $node): int
{
$main_status = $this->check($node->children['try']);
// Finding good heuristics is difficult.
// e.g. "return someFunctionThatMayThrow()" in try{} block would be inferred as STATUS_RETURN, but may actually be STATUS_THROW
- 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"