File Context.php
has 569 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Language;
Context
has 53 functions (exceeds 20 allowed). Consider refactoring. Open
class Context extends FileRef
{
/**
* @var string
* The namespace of the file.
The class Context has an overall complexity of 119 which is very high. The configured complexity threshold is 50. Open
class Context extends FileRef
{
/**
* @var string
* The namespace of the file.
- Exclude checks
Method getNamespaceMapFor
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getNamespaceMapFor(
int $flags,
string $name
): FullyQualifiedGlobalStructuralElement {
Function getThisPropertyIfOverridden
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getThisPropertyIfOverridden(string $name): ?UnionType
{
if (!$this->scope->hasVariableWithName(self::VAR_NAME_THIS_PROPERTIES)) {
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 withExitLoop
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function withExitLoop(Node $node): Context
{
$context = clone($this);
while ($context->loop_nodes) {
- 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 hasSuppressIssue
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function hasSuppressIssue(
CodeBase $code_base,
string $issue_name
): bool {
if ($code_base->hasFileLevelSuppression($this->file, $issue_name)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function warnAboutUnusedUseElements
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function warnAboutUnusedUseElements(CodeBase $code_base): void
{
foreach ($this->namespace_map as $flags => $entries_for_flag) {
foreach ($entries_for_flag as $namespace_map_entry) {
if ($namespace_map_entry->is_used) {
- 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 Context has 50 public methods and attributes. Consider reducing the number of public items to less than 45. Open
class Context extends FileRef
{
/**
* @var string
* The namespace of the file.
- Read upRead up
- Exclude checks
ExcessivePublicCount
Since: 0.1
A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.
Example
public class Foo {
public $value;
public $something;
public $var;
// [... more more public attributes ...]
public function doWork() {}
public function doMoreWork() {}
public function doWorkAgain() {}
// [... more more public methods ...]
}
Source https://phpmd.org/rules/codesize.html#excessivepubliccount
Method warnAboutUnusedUseElements
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function warnAboutUnusedUseElements(CodeBase $code_base): void
{
foreach ($this->namespace_map as $flags => $entries_for_flag) {
foreach ($entries_for_flag as $namespace_map_entry) {
if ($namespace_map_entry->is_used) {
Function withNamespaceMap
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function withNamespaceMap(
int $flags,
string $alias,
FullyQualifiedGlobalStructuralElement $target,
int $lineno,
- 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 withNamespaceMap
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
int $flags,
string $alias,
FullyQualifiedGlobalStructuralElement $target,
int $lineno,
CodeBase $code_base = null
Method warnDuplicateUse
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function warnDuplicateUse(CodeBase $code_base, FullyQualifiedGlobalStructuralElement $target, int $lineno, int $flags, string $alias): void
Function getNamespaceMapFor
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getNamespaceMapFor(
int $flags,
string $name
): FullyQualifiedGlobalStructuralElement {
- 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 $result;
Function getFunctionLikeInScope
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getFunctionLikeInScope(
CodeBase $code_base
): FunctionInterface {
$fqsen = $this->getFunctionLikeFQSEN();
- 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 Context has a coupling between objects value of 28. Consider to reduce the number of dependencies under 13. Open
class Context extends FileRef
{
/**
* @var string
* The namespace of the file.
- 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) {}
// ...
}