The method Issue::fromType() calls the typical debug function debug_print_backtrace() which is mostly only used during development. Open
\debug_print_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
- Read upRead up
- Exclude checks
DevelopmentCodeFragment
Since: 2.3.0
Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.
Example
class SuspectCode {
public function doSomething(array $items)
{
foreach ($items as $i => $item) {
// …
if ('qafoo' == $item) var_dump($i);
// …
}
}
}
Source https://phpmd.org/rules/design.html#developmentcodefragment
Method generateIssueMap
has 4385 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function generateIssueMap(): array
{
// phpcs:disable Generic.Files.LineLength
/**
* @var list<Issue>
File Issue.php
has 5330 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan;
The class Issue has 11 public methods. Consider refactoring Issue to keep number of public methods under 10. Open
class Issue
{
// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
// this is deliberate for issue names
// Issue::CATEGORY_SYNTAX
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Issue has an overall complexity of 50 which is very high. The configured complexity threshold is 50. Open
class Issue
{
// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
// this is deliberate for issue names
// Issue::CATEGORY_SYNTAX
- Exclude checks
Issue
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class Issue
{
// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
// this is deliberate for issue names
// Issue::CATEGORY_SYNTAX
Method sanityCheckErrorList
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function sanityCheckErrorList(array $error_list): void
{
$error_map = [];
$unique_type_id_set = [];
foreach ($error_list as $error) {
Function sanityCheckErrorList
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function sanityCheckErrorList(array $error_list): void
{
$error_map = [];
$unique_type_id_set = [];
foreach ($error_list as $error) {
- 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 maybeEmitWithParameters
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
string $issue_type,
int $lineno,
array $parameters,
Method shouldSuppressIssue
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
string $issue_type,
int $lineno,
array $parameters,
Method __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
string $type,
int $category,
int $severity,
string $template_raw,
int $remediation_difficulty,
Method emitWithParameters
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
string $type,
string $file,
int $line,
array $template_parameters,
Suggestion $suggestion = null,
Method __invoke
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
string $file,
int $line,
array $template_parameters = [],
Suggestion $suggestion = null,
int $column = 0
Method maybeEmit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
Context $context,
string $issue_type,
int $lineno,
...$parameters
Function getNextTypeId
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function getNextTypeId(array $issue_list, int $invalid_type_id): int
{
for ($id = $invalid_type_id + 1; true; $id++) {
foreach ($issue_list as $error) {
if ($error->getTypeId() === $id) {
- 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 ConfigPluginSet::instance()->shouldSuppressIssue(
$code_base,
$context,
$issue_type,
$lineno,
The class Issue has 5671 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Issue
{
// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
// this is deliberate for issue names
// Issue::CATEGORY_SYNTAX
- Exclude checks
The method generateIssueMap() has 4448 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private static function generateIssueMap(): array
{
// phpcs:disable Generic.Files.LineLength
/**
* @var list<Issue>
- Exclude checks