File TolerantASTConverter.php
has 2622 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\AST\TolerantASTConverter;
Method initHandleMap
has 1041 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function initHandleMap(): array
{
$closures = [
/** @return ?ast\Node */
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\Node {
Function initHandleMap
has a Cognitive Complexity of 180 (exceeds 5 allowed). Consider refactoring. Open
protected static function initHandleMap(): array
{
$closures = [
/** @return ?ast\Node */
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\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
TolerantASTConverter
has 86 functions (exceeds 20 allowed). Consider refactoring. Open
class TolerantASTConverter
{
// The latest stable version of php-ast.
// For something != 70, update the library's release.
public const AST_VERSION = 70;
Function resolveDocCommentForClosure
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
private static function resolveDocCommentForClosure(PhpParser\Node\Expression $node): ?string
{
$doc_comment = $node->getDocCommentText();
if (\Phan\Library\StringUtil::isNonZeroLengthString($doc_comment)) {
return $doc_comment;
- 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 phpParserStmtlistToAstNode
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserStmtlistToAstNode($parser_nodes, ?int $lineno, bool $return_null_on_empty = false): ?\ast\Node
{
if ($parser_nodes instanceof PhpParser\Node\Statement\CompoundStatementNode) {
$parser_nodes = $parser_nodes->statements;
} elseif ($parser_nodes instanceof PhpParser\Node\StatementNode) {
- 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 phpParserTypeToAstNode
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
protected static function phpParserTypeToAstNode($type, int $line): ?ast\Node
{
if (\is_null($type)) {
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 astStmtClass
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private static function astStmtClass(
int $flags,
?string $name,
?\ast\Node $extends,
?\Microsoft\PhpParser\node\classinterfaceclause $implements,
- 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 class TolerantASTConverter has 79 non-getter- and setter-methods. Consider refactoring TolerantASTConverter to keep number of methods under 25. Open
class TolerantASTConverter
{
// The latest stable version of php-ast.
// For something != 70, update the library's release.
public const AST_VERSION = 70;
- 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 TolerantASTConverter has an overall complexity of 525 which is very high. The configured complexity threshold is 50. Open
class TolerantASTConverter
{
// The latest stable version of php-ast.
// For something != 70, update the library's release.
public const AST_VERSION = 70;
- Exclude checks
Method phpParserTypeToAstNode
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function phpParserTypeToAstNode($type, int $line): ?ast\Node
{
if (\is_null($type)) {
return null;
}
Method resolveDocCommentForClosure
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function resolveDocCommentForClosure(PhpParser\Node\Expression $node): ?string
{
$doc_comment = $node->getDocCommentText();
if (\Phan\Library\StringUtil::isNonZeroLengthString($doc_comment)) {
return $doc_comment;
Function phpParserArrayToAstArray
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserArrayToAstArray(PhpParser\Node\Expression\ArrayCreationExpression $n, int $start_line): ast\Node
{
$ast_items = [];
$prev_was_element = false;
foreach ($n->arrayElements->children ?? [] as $item) {
- 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 phpParserUnionTypeToAstNode
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
protected static function phpParserUnionTypeToAstNode($type, ?PhpParser\Node\DelimitedList\QualifiedNameList $other_types, int $line): ?\ast\Node
{
$types = [];
if (!\is_null($type) && !($type instanceof Token && $type->kind === TokenKind::BarToken)) {
$result = static::phpParserTypeToAstNode($type, $line);
- 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 phpParserStmtlistToAstNode
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserStmtlistToAstNode($parser_nodes, ?int $lineno, bool $return_null_on_empty = false): ?\ast\Node
{
if ($parser_nodes instanceof PhpParser\Node\Statement\CompoundStatementNode) {
$parser_nodes = $parser_nodes->statements;
} elseif ($parser_nodes instanceof PhpParser\Node\StatementNode) {
Function phpParserExprListToExprList
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserExprListToExprList(PhpParser\Node\DelimitedList\ExpressionList $expressions_list, int $lineno): ast\Node
{
$children = [];
$expressions_children = $expressions_list->children;
foreach ($expressions_children as $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
Method astStmtClass
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function astStmtClass(
int $flags,
?string $name,
?\ast\Node $extends,
?\Microsoft\PhpParser\node\classinterfaceclause $implements,
Function parseMultiPartHeredoc
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function parseMultiPartHeredoc(PhpParser\Node\StringLiteral $n, array $children): ast\Node
{
$inner_node_parts = [];
$end_of_start_quote = self::$file_contents[$n->startQuote->start + $n->startQuote->length - 1];
$end_quote_text = $n->endQuote->getText(self::$file_contents);
- 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 phpParserArrayToAstArray
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserArrayToAstArray(PhpParser\Node\Expression\ArrayCreationExpression $n, int $start_line): ast\Node
{
$ast_items = [];
$prev_was_element = false;
foreach ($n->arrayElements->children ?? [] as $item) {
Function astStmtGroupUse
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function astStmtGroupUse(?int $type, ?string $prefix, array $uses, int $line): ast\Node
{
$flags = static::phpParserNamespaceUseKindToASTUseFlags($type);
$uses = new ast\Node(ast\AST_USE, 0, $uses, $line);
if ($flags === flags\USE_NORMAL) {
- 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 phpParserListToAstList
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserListToAstList(PhpParser\Node\Expression\ListIntrinsicExpression $n, int $start_line): ast\Node
{
$ast_items = [];
$prev_was_element = false;
foreach ($n->listElements->children ?? [] as $item) {
- 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 parseMultiPartHeredoc
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function parseMultiPartHeredoc(PhpParser\Node\StringLiteral $n, array $children): ast\Node
{
$inner_node_parts = [];
$end_of_start_quote = self::$file_contents[$n->startQuote->start + $n->startQuote->length - 1];
$end_quote_text = $n->endQuote->getText(self::$file_contents);
Method phpParserIfStmtToAstIfStmt
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserIfStmtToAstIfStmt(PhpParser\Node\Statement\IfStatementNode $node, int $start_line): ast\Node
{
$if_elem = static::astIfElem(
static::phpParserNodeToAstNode($node->expression),
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable return_null_on_empty is false.
Method phpParserVisibilityToAstVisibility
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserVisibilityToAstVisibility(array $visibility, bool $automatically_add_public = true): int
{
$ast_visibility = 0;
foreach ($visibility as $token) {
switch ($token->kind) {
Function phpParserVisibilityToAstVisibility
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserVisibilityToAstVisibility(array $visibility, bool $automatically_add_public = true): int
{
$ast_visibility = 0;
foreach ($visibility as $token) {
switch ($token->kind) {
- 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 parseMultiPartRegularString
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function parseMultiPartRegularString(PhpParser\Node\StringLiteral $n, array $children): ast\Node
{
$inner_node_parts = [];
$start_quote_text = static::tokenToString($n->startQuote);
$end_quote_text = $n->endQuote->getText(self::$file_contents);
- 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 astDeclClosure
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
bool $by_ref,
bool $static,
ast\Node $params,
?\ast\Node $uses,
ast\Node $stmts,
Method phpParserExprListToExprList
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserExprListToExprList(PhpParser\Node\DelimitedList\ExpressionList $expressions_list, int $lineno): ast\Node
{
$children = [];
$expressions_children = $expressions_list->children;
foreach ($expressions_children as $expr) {
Method astNodeBinaryop
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function astNodeBinaryop(int $flags, PhpParser\Node\Expression\BinaryExpression $n, int $start_line)
{
try {
$left_node = static::phpParserNodeToAstNode($n->leftOperand);
} catch (InvalidNodeException $_) {
Method phpParserListToAstList
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function phpParserListToAstList(PhpParser\Node\Expression\ListIntrinsicExpression $n, int $start_line): ast\Node
{
$ast_items = [];
$prev_was_element = false;
foreach ($n->listElements->children ?? [] as $item) {
Method newAstDecl
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function newAstDecl(int $kind, int $flags, array $children, int $lineno, string $doc_comment = null, string $name = null, int $end_lineno = 0, int $decl_id = -1): ast\Node
Method astDeclFunction
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
bool $by_ref,
string $name,
ast\Node $params,
?\ast\Node $return_type,
?\ast\Node $stmts,
Method astStmtClass
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
int $flags,
?string $name,
?\ast\Node $extends,
?\Microsoft\PhpParser\node\classinterfaceclause $implements,
?\ast\Node $stmts,
Function interfaceBaseClauseToNode
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function interfaceBaseClauseToNode(?\Microsoft\PhpParser\Node\InterfaceBaseClause $node): ?\ast\Node
{
if (!$node instanceof PhpParser\Node\InterfaceBaseClause) {
// TODO: real placeholder?
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
Method astNodeParam
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function astNodeParam(bool $is_nullable, bool $by_ref, bool $variadic, ?\ast\Node $type, string $name, $default, int $line): ast\Node
Function phpParserPropelemToAstPropelem
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserPropelemToAstPropelem($n, ?string $doc_comment): ast\Node
{
if ($n instanceof PhpParser\Node\Expression\AssignmentExpression) {
$name_node = $n->leftOperand;
if (!($name_node instanceof PhpParser\Node\Expression\Variable)) {
- 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 phpParserClosureUsesToAstClosureUses
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserClosureUsesToAstClosureUses(
?\Microsoft\PhpParser\Node\DelimitedList\UseVariableNameList $uses,
int $line
): ?\ast\Node {
$children = $uses->children ?? [];
- 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 astNodeBinaryop
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function astNodeBinaryop(int $flags, PhpParser\Node\Expression\BinaryExpression $n, int $start_line)
{
try {
$left_node = static::phpParserNodeToAstNode($n->leftOperand);
} catch (InvalidNodeException $_) {
- 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 astNodeMethodCall
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function astNodeMethodCall(int $kind, $expr, $method, ast\Node $args, int $start_line): ast\Node
Function phpParserMatchConditionListToAstNode
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserMatchConditionListToAstNode(?PhpParser\Node\DelimitedList\MatchArmConditionList $condition_list): ?ast\Node
{
if (!$condition_list) {
throw new InvalidNodeException();
}
- 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 phpParserMatchArmListToAstMatchArmList
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected static function phpParserMatchArmListToAstMatchArmList(?\Microsoft\PhpParser\Node\DelimitedList\MatchExpressionArmList $arms, int $start_line): ast\Node
{
$ast_arms = [];
foreach ($arms->children ?? [] as $arm) {
if (!$arm instanceof PhpParser\Node\MatchArm) {
- 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 phpParserNamespaceUseListToAstUseList
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserNamespaceUseListToAstUseList(array $uses): array
{
$ast_uses = [];
foreach ($uses as $use_clause) {
if (!($use_clause instanceof PhpParser\Node\NamespaceUseGroupClause)) {
- 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 static::astNodeBinaryop($ast_kind, $n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_CLONE, 0, ['expr' => static::phpParserNodeToAstNode($n->expression)], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_INCLUDE_OR_EVAL,
$flags,
['expr' => static::phpParserNodeToAstNode($n->expression)],
$start_line
Avoid too many return
statements within this method. Open
return static::phpParserNodeToAstNode($n->rightOperand);
Avoid too many return
statements within this method. Open
return static::astNodeAssign(
$var_node,
$expr_node,
$start_line,
$n->byRef !== null
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_NAME, flags\NAME_NOT_FQ, ['name' => $str], $start_line);
Avoid too many return
statements within this method. Open
return static::newASTDecl(
ast\AST_ARROW_FUNC,
($n->byRefToken !== null ? flags\FUNC_RETURNS_REF : 0) | ($n->staticModifier !== null ? flags\MODIFIER_STATIC : null),
[
'params' => static::phpParserParamsToAstParams($n->parameters, $start_line),
Avoid too many return
statements within this method. Open
return static::astNodeCall(
static::phpParserNonValueNodeToAstNode($callable_expression),
$arg_list,
$start_line
);
Avoid too many return
statements within this method. Open
return static::phpParserArrayToAstArray($n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node($type, 0, ['var' => static::phpParserNodeToAstNode($n->operand)], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_CAST,
$ast_kind,
['expr' => static::phpParserNodeToAstNode($n->operand)],
static::getEndLine($n) ?: $start_line
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_STATIC_PROP,
0,
[
'class' => static::phpParserNonValueNodeToAstNode($n->scopeResolutionQualifier),
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_EMPTY, 0, ['expr' => static::phpParserNodeToAstNode($n->expression)], $start_line);
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return static::phpParserMemberAccessExpressionToAstProp($n, $start_line);
Avoid too many return
statements within this method. Open
return static::astNodeAssignop($ast_kind, $n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_EXIT, 0, ['expr' => $expr_node], $start_line);
Avoid too many return
statements within this method. Open
return static::phpParserNodeToAstNode($n->expression);
Avoid too many return
statements within this method. Open
return static::phpParserClassConstFetchToAstClassConstFetch($n->scopeResolutionQualifier, $member_name, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_INSTANCEOF, 0, [
'expr' => static::phpParserNodeToAstNode($n->leftOperand),
'class' => static::phpParserNonValueNodeToAstNode($n->rightOperand),
], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_UNARY_OP,
$ast_kind,
['expr' => static::phpParserNodeToAstNode($n->operand)],
$start_line
Avoid too many return
statements within this method. Open
return static::phpParserNodeToAstNode($n->expression);
Avoid too many return
statements within this method. Open
return static::astNodeStaticCall(
static::phpParserNonValueNodeToAstNode($callable_expression->scopeResolutionQualifier),
static::phpParserNodeToAstNode($callable_expression->memberName),
$arg_list,
$start_line
Avoid too many return
statements within this method. Open
return static::phpParserListToAstList($n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_UNARY_OP,
flags\UNARY_SILENCE,
['expr' => static::phpParserNodeToAstNode($n->operand)],
$start_line
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_VAR, 0, ['name' => $name_node], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_INCLUDE_OR_EVAL,
flags\EXEC_EVAL,
['expr' => static::phpParserNodeToAstNode($n->expression)],
$start_line
Avoid too many return
statements within this method. Open
return $str;
Avoid too many return
statements within this method. Open
return new ast\Node($type, 0, ['var' => static::phpParserNodeToAstNode($n->operand)], $start_line);
Avoid too many return
statements within this method. Open
return static::astDeclClosure(
$n->byRefToken !== null,
$n->staticModifier !== null,
static::phpParserParamsToAstParams($n->parameters, $start_line),
static::phpParserClosureUsesToAstClosureUses($use_variable_name_list, $start_line),
Avoid too many return
statements within this method. Open
return static::astNodeMethodCall(
$callable_expression->arrowToken->kind === TokenKind::QuestionArrowToken ? ast\AST_NULLSAFE_METHOD_CALL : ast\AST_METHOD_CALL,
static::phpParserNonValueNodeToAstNode($callable_expression->dereferencableExpression),
static::phpParserNodeToAstNode($callable_expression->memberName),
$arg_list,
Avoid too many return
statements within this method. Open
return $e;
Avoid too many return
statements within this method. Open
return $expr;
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_NEW, 0, [
'class' => $class_node,
'args' => static::phpParserArgListToAstArgList($n->argumentExpressionList, $start_line),
], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_PRINT,
0,
['expr' => static::phpParserNodeToAstNode($n->expression)],
$start_line
Avoid too many return
statements within this method. Open
return static::phpParserNodeToAstNode($n->expression);
Avoid too many return
statements within this method. Open
return static::astStmtCatch(
$catch_list_node,
$variableName !== null ? static::variableTokenToString($variableName) : null,
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable return_null_on_empty is false.
static::phpParserStmtlistToAstNode($n->compoundStatement, $start_line, false),
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return \count($static_nodes) === 1 ? $static_nodes[0] : $static_nodes;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $doc_comment;
Avoid too many return
statements within this method. Open
return (float)$text;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_TRAIT_ALIAS, $flags, $children, $start_line);
Avoid too many return
statements within this method. Open
return $doc_comment;
Avoid too many return
statements within this method. Open
return \bindec($text);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_DO_WHILE,
0,
[
'stmts' => static::phpParserStmtlistToAstNode($n->statement, $start_line, false),
Avoid too many return
statements within this method. Open
return static::phpParserStmtlistToAstNode($n->compoundStatement, $start_line, false);
Avoid too many return
statements within this method. Open
return \count($global_nodes) === 1 ? $global_nodes[0] : $global_nodes;
Avoid too many return
statements within this method. Open
return \count($stmts) === 1 ? $stmts[0] : $stmts;
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_FOR,
0,
[
'init' => $n->forInitializer !== null ? static::phpParserExprListToExprList($n->forInitializer, $start_line) : null,
Avoid too many return
statements within this method. Open
return self::phpParserMatchToAstMatch($n, $start_line);
Avoid too many return
statements within this method. Open
return $label;
Avoid too many return
statements within this method. Open
return \count($ast_echos) === 1 ? $ast_echos[0] : $ast_echos;
Avoid too many return
statements within this method. Open
return $inner_node;
Avoid too many return
statements within this method. Open
return new ast\Node($kind, 0, ['depth' => $breakout_level], $start_line);
Avoid too many return
statements within this method. Open
return \intval($text, 8);
Avoid too many return
statements within this method. Open
return \hexdec($text);
Avoid too many return
statements within this method. Open
return static::astStmtClass(
static::phpParserClassModifierToAstClassFlags($n->abstractOrFinalModifier),
static::tokenToString($n->name),
$base_class !== null ? static::phpParserNonValueNodeToAstNode($base_class) : null,
$n->classInterfaceClause,
Avoid too many return
statements within this method. Open
return []; // For the beginning/end of files
Avoid too many return
statements within this method. Open
return static::phpParserPropertyToAstNode($n, $start_line);
Avoid too many return
statements within this method. Open
return $as_int;
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_FOREACH,
0,
[
'expr' => static::phpParserNodeToAstNode($n->forEachCollectionName),
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_MAGIC_CONST,
self::MAGIC_CONST_LOOKUP[\strtoupper($imploded_parts)],
[],
self::getStartLine($part)
Avoid too many return
statements within this method. Open
return static::phpParserIfStmtToAstIfStmt($n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_SHELL_EXEC, 0, ['expr' => $inner_node], isset($children[0]) ? self::getStartLine($children[0]) : $start_line);
Avoid too many return
statements within this method. Open
return static::phpParserClassConstToAstNode($n, $start_line);
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return static::phpParserThrowToASTThrow($n, $start_line);
Avoid too many return
statements within this method. Open
return $statement;
Avoid too many return
statements within this method. Open
return new ast\Node(
$kind,
0,
$children,
$start_line
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $results;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return \octdec(substr($text, 0, \strcspn($text, '89')));
Avoid too many return
statements within this method. Open
return static::astDeclFunction(
$n->byRefToken !== null,
static::tokenToString($name),
static::phpParserParamsToAstParams($n->parameters, $start_line),
$ast_return_type,
Avoid too many return
statements within this method. Open
return static::astStmtClass(
flags\CLASS_INTERFACE,
static::tokenToString($n->name),
static::interfaceBaseClauseToNode($n->interfaceBaseClause),
null,
Avoid too many return
statements within this method. Open
return static::astStmtClass(
flags\CLASS_TRAIT,
static::tokenToString($n->name),
null,
null,
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_NAME,
flags\NAME_NOT_FQ,
['name' => static::tokenToString($n->children)],
$start_line
Avoid too many return
statements within this method. Open
return static::phpParserSwitchListToAstSwitch($n);
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return static::astNodeTry(
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable return_null_on_empty is false.
static::phpParserStmtlistToAstNode($n->compoundStatement, $start_line, false), // $n->try
static::phpParserCatchlistToAstCatchlist($n->catchClauses ?? [], $start_line),
$finally_clause !== null ? static::phpParserStmtlistToAstNode($finally_clause->compoundStatement, self::getStartLine($finally_clause), false) : null,
Avoid too many return
statements within this method. Open
return $children;
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_USE_TRAIT,
0,
[
'traits' => static::phpParserNameListToAstNameList($n->traitNameList->children ?? [], $start_line),
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_TRAIT_PRECEDENCE, 0, $children, $start_line);
Avoid too many return
statements within this method. Open
return static::astNodeWhile(
static::phpParserNodeToAstNode($n->expression),
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable return_null_on_empty is false.
static::phpParserStmtlistToAstNode($n->statements, $start_line, false),
$start_line
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_GOTO, 0, ['label' => static::tokenToString($n->name)], $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_NAME, $ast_kind, ['name' => $imploded_parts], $start_line);
Avoid too many return
statements within this method. Open
return static::astStmtDeclare(
static::phpParserDeclareListToAstDeclares($directive, $start_line, $doc_comment),
$n->statements !== null ? static::phpParserStmtlistToAstNode($n->statements, $start_line, true) : null,
$start_line
);
Avoid too many return
statements within this method. Open
return static::phpParserThrowToASTThrow($n, $start_line);
Avoid too many return
statements within this method. Open
return [$label, $statement];
Avoid too many return
statements within this method. Open
return $closures;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return static::astNodeParam(
$n->questionToken !== null,
$n->byRefToken !== null,
$n->dotDotDotToken !== null,
static::phpParserUnionTypeToAstNode($n->typeDeclaration, $n->otherTypeDeclarations, $type_line),
Avoid too many return
statements within this method. Open
return static::newAstDecl(
ast\AST_METHOD,
static::phpParserVisibilityToAstVisibility($n->modifiers) | ($n->byRefToken !== null ? flags\FUNC_RETURNS_REF : 0),
[
'params' => static::phpParserParamsToAstParams($n->parameters, $start_line),
Avoid too many return
statements within this method. Open
return static::phpParserConstToAstNode($n, $start_line);
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_ECHO,
0,
['expr' => static::tokenToRawString($n->text)],
$start_line
Avoid too many return
statements within this method. Open
return new ast\Node(
ast\AST_NAMESPACE,
0,
[
'name' => $name_node !== null ? static::phpParserNameToString($name_node) : null,
Avoid too many return
statements within this method. Open
return new ast\Node(ast\AST_RETURN, 0, ['expr' => $expr_node], $start_line);
Avoid too many return
statements within this method. Open
return null;
Function phpParserArgListToAstArgList
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserArgListToAstArgList(?\Microsoft\PhpParser\node\delimitedlist\argumentexpressionlist $args, int $line): ast\Node
{
$ast_args = [];
foreach ($args->children ?? [] as $arg) {
if ($arg instanceof Token && $arg->kind === TokenKind::CommaToken) {
- 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 parseCodeAsPHPAST
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function parseCodeAsPHPAST(string $file_contents, int $version, array &$errors = [], Cache $cache = null): \ast\Node
{
if (!\in_array($version, self::SUPPORTED_AST_VERSIONS, true)) {
throw new \InvalidArgumentException(sprintf("Unexpected version: want %s, got %d", \implode(', ', self::SUPPORTED_AST_VERSIONS), $version));
}
- 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 phpParserConstToAstNode
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function phpParserConstToAstNode(PhpParser\Node\Statement\ConstDeclaration $n, int $start_line): ast\Node
{
$const_elems = [];
$doc_comment = $n->getDocCommentText();
foreach ($n->constElements->children ?? [] as $i => $prop) {
- 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 phpParserStmtlistToAstNode() has an NPath complexity of 504. The configured NPath complexity threshold is 200. Open
private static function phpParserStmtlistToAstNode($parser_nodes, ?int $lineno, bool $return_null_on_empty = false): ?\ast\Node
{
if ($parser_nodes instanceof PhpParser\Node\Statement\CompoundStatementNode) {
$parser_nodes = $parser_nodes->statements;
} elseif ($parser_nodes instanceof PhpParser\Node\StatementNode) {
- 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 initHandleMap() has 1161 lines of code. Current threshold is set to 100. Avoid really long methods. Open
protected static function initHandleMap(): array
{
$closures = [
/** @return ?ast\Node */
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\Node {
- Exclude checks
The method resolveDocCommentForClosure() has an NPath complexity of 70682. The configured NPath complexity threshold is 200. Open
private static function resolveDocCommentForClosure(PhpParser\Node\Expression $node): ?string
{
$doc_comment = $node->getDocCommentText();
if (\Phan\Library\StringUtil::isNonZeroLengthString($doc_comment)) {
return $doc_comment;
- 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 TolerantASTConverter has 3175 lines of code. Current threshold is 1000. Avoid really long classes. Open
class TolerantASTConverter
{
// The latest stable version of php-ast.
// For something != 70, update the library's release.
public const AST_VERSION = 70;
- Exclude checks
The method initHandleMap() has an NPath complexity of 9223372036854775807. The configured NPath complexity threshold is 200. Open
protected static function initHandleMap(): array
{
$closures = [
/** @return ?ast\Node */
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\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 phpParserUnionTypeToAstNode() has an NPath complexity of 210. The configured NPath complexity threshold is 200. Open
protected static function phpParserUnionTypeToAstNode($type, ?PhpParser\Node\DelimitedList\QualifiedNameList $other_types, int $line): ?\ast\Node
{
$types = [];
if (!\is_null($type) && !($type instanceof Token && $type->kind === TokenKind::BarToken)) {
$result = static::phpParserTypeToAstNode($type, $line);
- 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 initHandleMap() has a Cyclomatic Complexity of 162. The configured cyclomatic complexity threshold is 10. Open
protected static function initHandleMap(): array
{
$closures = [
/** @return ?ast\Node */
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\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 resolveDocCommentForClosure() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10. Open
private static function resolveDocCommentForClosure(PhpParser\Node\Expression $node): ?string
{
$doc_comment = $node->getDocCommentText();
if (\Phan\Library\StringUtil::isNonZeroLengthString($doc_comment)) {
return $doc_comment;
- 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 phpParserArrayToAstArray() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private static function phpParserArrayToAstArray(PhpParser\Node\Expression\ArrayCreationExpression $n, int $start_line): ast\Node
{
$ast_items = [];
$prev_was_element = false;
foreach ($n->arrayElements->children ?? [] as $item) {
- 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 phpParserUnionTypeToAstNode() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
protected static function phpParserUnionTypeToAstNode($type, ?PhpParser\Node\DelimitedList\QualifiedNameList $other_types, int $line): ?\ast\Node
{
$types = [];
if (!\is_null($type) && !($type instanceof Token && $type->kind === TokenKind::BarToken)) {
$result = static::phpParserTypeToAstNode($type, $line);
- 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 phpParserTypeToAstNode() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
protected static function phpParserTypeToAstNode($type, int $line): ?ast\Node
{
if (\is_null($type)) {
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 astStmtClass() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private static function astStmtClass(
int $flags,
?string $name,
?\ast\Node $extends,
?\Microsoft\PhpParser\node\classinterfaceclause $implements,
- 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 phpParserVisibilityToAstVisibility() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
private static function phpParserVisibilityToAstVisibility(array $visibility, bool $automatically_add_public = true): int
{
$ast_visibility = 0;
foreach ($visibility as $token) {
switch ($token->kind) {
- 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 phpParserStmtlistToAstNode() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
private static function phpParserStmtlistToAstNode($parser_nodes, ?int $lineno, bool $return_null_on_empty = false): ?\ast\Node
{
if ($parser_nodes instanceof PhpParser\Node\Statement\CompoundStatementNode) {
$parser_nodes = $parser_nodes->statements;
} elseif ($parser_nodes instanceof PhpParser\Node\StatementNode) {
- 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 TolerantASTConverter has a coupling between objects value of 119. Consider to reduce the number of dependencies under 13. Open
class TolerantASTConverter
{
// The latest stable version of php-ast.
// For something != 70, update the library's release.
public const AST_VERSION = 70;
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (\is_null($callback_map)) {
$callback_map = static::initHandleMap();
/**
* @param PhpParser\Node|Token $n
* @return ast\Node - Not a real node, but a node indicating the TODO
- 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 134.
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 (\is_null($callback_map)) {
$callback_map = static::initHandleMap();
/**
* @param PhpParser\Node|Token $n
* @return ast\Node - Not a real node, but a node indicating the TODO
- 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 134.
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
'Microsoft\PhpParser\Node\Statement\ReturnStatement' => static function (PhpParser\Node\Statement\ReturnStatement $n, int $start_line): ast\Node {
$e = $n->expression;
$expr_node = $e !== null ? static::phpParserNodeToAstNode($e) : null;
return new ast\Node(ast\AST_RETURN, 0, ['expr' => $expr_node], $start_line);
},
- 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 90.
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
'Microsoft\PhpParser\Node\Expression\ExitIntrinsicExpression' => static function (PhpParser\Node\Expression\ExitIntrinsicExpression $n, int $start_line): ast\Node {
$expression = $n->expression;
$expr_node = $expression !== null ? static::phpParserNodeToAstNode($expression) : null;
return new ast\Node(ast\AST_EXIT, 0, ['expr' => $expr_node], $start_line);
},
- 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 90.
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 $n. Configured minimum length is 3. Open
final protected static function getEndLine($n): int
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
'Microsoft\PhpParser\Node\SourceFileNode' => static function (PhpParser\Node\SourceFileNode $n, int $start_line): ?\ast\Node {
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function astNodeBinaryop(int $flags, PhpParser\Node\Expression\BinaryExpression $n, int $start_line)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function parseMultiPartString(PhpParser\Node\StringLiteral $n, array $children): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserPropertyToAstNode(PhpParser\Node\PropertyDeclaration $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserConstToAstNode(PhpParser\Node\Statement\ConstDeclaration $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserMemberAccessExpressionToAstProp(PhpParser\Node\Expression\MemberAccessExpression $n, int $start_line): \ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserConstelemToAstConstelem(PhpParser\Node\ConstElement $n, ?string $doc_comment): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function variableTokenToString(Token $n): string
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function parseMultiPartHeredoc(PhpParser\Node\StringLiteral $n, array $children): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserPropelemToAstPropelem($n, ?string $doc_comment): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserListToAstList(PhpParser\Node\Expression\ListIntrinsicExpression $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $s. Configured minimum length is 3. Open
$s = $inner_node_parts[$i];
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $c. Configured minimum length is 3. Open
$c = $text[1];
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function astNodeAssignop(int $flags, PhpParser\Node\Expression\BinaryExpression $n, int $start_line)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function normalizeTernaryExpression(TernaryExpression $n): TernaryExpression
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
protected static function phpParserMatchToAstMatch(PhpParser\Node\Expression\MatchExpression $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
protected static function debugDumpNodeOrToken($n): string
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
protected static function phpParserNodeToAstNodeOrPlaceholderExpr($n)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserArrayToAstArray(PhpParser\Node\Expression\ArrayCreationExpression $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function newPlaceholderExpression($n): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserThrowToASTThrow(object $n, int $start_line): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function parseMultiPartRegularString(PhpParser\Node\StringLiteral $n, array $children): ast\Node
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function parseQuotedString(PhpParser\Node\StringLiteral $n): string
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function tokenToString(Token $n): string
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
protected static function phpParserNodeToAstNode($n)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function tokenToRawString(Token $n): string
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
$n = \count($types);
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function tokenToScalar(Token $n)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
protected static function phpParserNonValueNodeToAstNode($n)
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
final protected static function getStartLine($n): int
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $_. Configured minimum length is 3. Open
'Microsoft\PhpParser\MissingToken' => static function (PhpParser\MissingToken $unused_node, int $_): 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $n. Configured minimum length is 3. Open
private static function phpParserClassConstToAstNode(PhpParser\Node\ClassConstDeclaration $n, int $start_line): ast\Node
- 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;
}
}
}