File Clazz.php
has 2467 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Language\Element;
Clazz
has 123 functions (exceeds 20 allowed). Consider refactoring. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
Method fromReflectionClass
has 162 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function fromReflectionClass(
CodeBase $code_base,
ReflectionClass $class
): Clazz {
// Build a set of flags based on the constitution
Method getPropertyByNameInContext
has 133 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getPropertyByNameInContext(
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
Function fromReflectionClass
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public static function fromReflectionClass(
CodeBase $code_base,
ReflectionClass $class
): Clazz {
// Build a set of flags based on the constitution
- 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 getPropertyByNameInContext
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
public function getPropertyByNameInContext(
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
- 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 addMethod
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function addMethod(
CodeBase $code_base,
Method $method,
Option $type_option
): void {
- 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 Clazz has 27 public methods. Consider refactoring Clazz to keep number of public methods under 10. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Clazz has an overall complexity of 488 which is very high. The configured complexity threshold is 50. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- Exclude checks
The class Clazz has 51 non-getter- and setter-methods. Consider refactoring Clazz to keep number of methods under 25. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- 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
Method addMethod
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addMethod(
CodeBase $code_base,
Method $method,
Option $type_option
): void {
Function importMixin
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
private function importMixin(CodeBase $code_base, Type $type): void
{
$fqsen = FullyQualifiedClassName::fromType($type);
if (!$code_base->hasClassWithFQSEN($fqsen) || $fqsen === $this->fqsen) {
Issue::maybeEmit(
- 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 getConstantByNameInContext
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getConstantByNameInContext(
CodeBase $code_base,
string $name,
Context $context
): ClassConstant {
Method importAncestorClass
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function importAncestorClass(
CodeBase $code_base,
Clazz $class,
Option $type_option
): void {
Function toStubSignature
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function toStubSignature(CodeBase $code_base): string
{
$string = '';
if ($this->isFinal()) {
- 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 importAncestorClass
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function importAncestorClass(
CodeBase $code_base,
Clazz $class,
Option $type_option
): void {
- 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 adaptInheritedMethodFromTrait
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function adaptInheritedMethodFromTrait(Method $method): Method
{
$method_flags = $method->getFlags();
if (Flags::bitVectorHasState($method_flags, \ast\flags\MODIFIER_PRIVATE)) {
$method = $method->createUseAlias($this, $method->getName(), \ast\flags\MODIFIER_PRIVATE);
Function adaptInheritedMethodFromTrait
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private function adaptInheritedMethodFromTrait(Method $method): Method
{
$method_flags = $method->getFlags();
if (Flags::bitVectorHasState($method_flags, \ast\flags\MODIFIER_PRIVATE)) {
$method = $method->createUseAlias($this, $method->getName(), \ast\flags\MODIFIER_PRIVATE);
- 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 addProperty
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addProperty(
CodeBase $code_base,
Property $property,
Option $type_option,
bool $from_trait = false
Function importAncestorClasses
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function importAncestorClasses(CodeBase $code_base): void
{
if (!$this->isFirstExecution(__METHOD__)) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method checkPropertyCompatibility
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function checkPropertyCompatibility(
CodeBase $code_base,
Property $inherited_property,
Property $overriding_property
): void {
Method setMagicMethodMap
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setMagicMethodMap(
array $magic_method_map,
CodeBase $code_base
): bool {
if (count($magic_method_map) === 0) {
Method toStubSignature
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function toStubSignature(CodeBase $code_base): string
{
$string = '';
if ($this->isFinal()) {
Function checkPropertyCompatibility
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function checkPropertyCompatibility(
CodeBase $code_base,
Property $inherited_property,
Property $overriding_property
): void {
- 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 setParentType
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function setParentType(Type $parent_type, int $lineno = 0): void
{
if ($this->getInternalScope()->hasAnyTemplateType()) {
// Get a reference to the local list of templated
// types. We'll use this to map templated types on the
- 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 toStubInfo
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toStubInfo(CodeBase $code_base): array
{
$signature = $this->toStubSignature($code_base);
$stub = $signature;
Method importAncestorClasses
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function importAncestorClasses(CodeBase $code_base): void
{
if (!$this->isFirstExecution(__METHOD__)) {
return;
}
Method importMixin
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function importMixin(CodeBase $code_base, Type $type): void
{
$fqsen = FullyQualifiedClassName::fromType($type);
if (!$code_base->hasClassWithFQSEN($fqsen) || $fqsen === $this->fqsen) {
Issue::maybeEmit(
Method hydrateConstantsOnce
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function hydrateConstantsOnce(CodeBase $code_base): void
{
foreach ($this->getAncestorFQSENList() as $fqsen) {
if ($code_base->hasClassWithFQSEN($fqsen)) {
$code_base->getClassByFQSENWithoutHydrating(
Method inheritConstant
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function inheritConstant(
CodeBase $code_base,
ClassConstant $constant
): void {
$constant_fqsen = FullyQualifiedClassConstantName::make(
Method analyze
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
final public function analyze(CodeBase $code_base): void
{
if ($this->isPHPInternal()) {
return;
}
Function analyzeInheritedMethods
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function analyzeInheritedMethods(CodeBase $code_base): void
{
if ($this->isClass() && !$this->isAbstract()) {
foreach ($this->getMethodMap($code_base) as $method) {
if ($method->getRealDefiningFQSEN() === $method->getFQSEN()) {
- 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 addProperty
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function addProperty(
CodeBase $code_base,
Property $property,
Option $type_option,
bool $from_trait = false
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getGenericConstructorBuilder
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getGenericConstructorBuilder(CodeBase $code_base): array
{
return $this->memoize(
'template_type_resolvers',
/**
Method getSettersMap
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getSettersMap(CodeBase $code_base): array
{
return $this->memoize(
__METHOD__,
/**
Method setMagicPropertyMap
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setMagicPropertyMap(
array $magic_property_map,
CodeBase $code_base
): bool {
if (count($magic_property_map) === 0) {
The class Clazz has 92 public methods and attributes. Consider reducing the number of public items to less than 45. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- 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 setParentType
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setParentType(Type $parent_type, int $lineno = 0): void
{
if ($this->getInternalScope()->hasAnyTemplateType()) {
// Get a reference to the local list of templated
// types. We'll use this to map templated types on the
Function checkConstantCompatibility
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function checkConstantCompatibility(
CodeBase $code_base,
ClassConstant $inherited_constant,
ClassConstant $overriding_constant
): void {
- 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 getAncestorElement
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function getAncestorElement(CodeBase $code_base, FullyQualifiedClassName $ancestor_fqsen, ClassElement $element): ?ClassElement
{
if (!$code_base->hasClassWithFQSEN($ancestor_fqsen)) {
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 setMagicMethodMap
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function setMagicMethodMap(
array $magic_method_map,
CodeBase $code_base
): bool {
if (count($magic_method_map) === 0) {
- 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 getGettersMap
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getGettersMap(CodeBase $code_base): array
{
if ($this->isInterface()) {
return [];
}
Method checkConstantCompatibility
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function checkConstantCompatibility(
CodeBase $code_base,
ClassConstant $inherited_constant,
ClassConstant $overriding_constant
): void {
Method importTraitAdaptations
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function importTraitAdaptations(
CodeBase $code_base,
Clazz $class,
TraitAdaptations $trait_adaptations,
Option $type_option
Method importParentClass
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function importParentClass(CodeBase $code_base): void
{
if (!$this->isFirstExecution(__METHOD__)) {
return;
}
Method emitWrongInheritanceCategoryWarning
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function emitWrongInheritanceCategoryWarning(
CodeBase $code_base,
Clazz $ancestor,
string $expected_inheritance_category,
int $lineno
Method getAncestorElement
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getAncestorElement(CodeBase $code_base, FullyQualifiedClassName $ancestor_fqsen, ClassElement $element): ?ClassElement
{
if (!$code_base->hasClassWithFQSEN($ancestor_fqsen)) {
return null;
}
Method __construct
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
Context $context,
string $name,
UnionType $type,
int $flags,
FullyQualifiedClassName $fqsen,
Function getMarkupDescription
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getMarkupDescription(): string
{
$fqsen = $this->getFQSEN();
$string = '';
$namespace = \ltrim($fqsen->getNamespace(), '\\');
- 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 importConstantsFromAncestorClasses
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function importConstantsFromAncestorClasses(CodeBase $code_base): void
{
if (!$this->isFirstExecution(__METHOD__)) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function hasFlagsRecursive
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function hasFlagsRecursive(CodeBase $code_base, int $flags): bool
{
$current = $this;
$checked = [];
while (true) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function resolveParentTemplateType
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function resolveParentTemplateType(array $template_parameter_type_map): UnionType
{
if (\count($template_parameter_type_map) === 0) {
return UnionType::empty();
}
- 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 importTraitAdaptations
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function importTraitAdaptations(
CodeBase $code_base,
Clazz $class,
TraitAdaptations $trait_adaptations,
Option $type_option
- 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 analyzeClassConstantOverrides
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function analyzeClassConstantOverrides(CodeBase $code_base, array $original_declared_class_constants): void
{
foreach ($original_declared_class_constants as $constant) {
if ($constant->isOverrideIntended() && !$constant->isOverride()) {
if ($constant->checkHasSuppressIssueAndIncrementCount(Issue::CommentOverrideOnNonOverrideConstant)) {
- 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 getPropertyByNameInContext
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
Node $node = null,
Function addReference
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function addReference(FileRef $file_ref): void
{
if (Config::get_track_references()) {
// Currently, we don't need to track references to PHP-internal methods/functions/constants
// such as PHP_VERSION, strlen(), Closure::bind(), etc.
- 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 analyzePropertyOverrides
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function analyzePropertyOverrides(CodeBase $code_base, array $original_declared_properties): void
{
foreach ($original_declared_properties as $property) {
if ($property->isOverrideIntended() && !$property->isOverride()) {
if ($property->checkHasSuppressIssueAndIncrementCount(Issue::CommentOverrideOnNonOverrideProperty)) {
- 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 $code_base->getClassConstantByFQSEN($constant_fqsen);
Avoid too many return
statements within this method. Open
return $method->toStub($is_interface);
Avoid too many return
statements within this method. Open
return $ancestor_class->getPropertyByName($code_base, $name);
Avoid too many return
statements within this method. Open
return $prop_name;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return Type::fromType($this->parent_type, $parent_template_parameter_type_list)->asPHPDocUnionType();
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 true;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $mapped_parameter;
Avoid too many return
statements within this method. Open
return [$namespace, $stub];
Function importParentClass
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function importParentClass(CodeBase $code_base): void
{
if (!$this->isFirstExecution(__METHOD__)) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function emitExtendsFinalClassWarning
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function emitExtendsFinalClassWarning(
CodeBase $code_base,
Clazz $ancestor
): void {
$context = $this->getContext();
- 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 getConstantByNameInContext
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getConstantByNameInContext(
CodeBase $code_base,
string $name,
Context $context
): ClassConstant {
- 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 computeSetPropertyName
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function computeSetPropertyName(Node $node, string $expected_parameter_name): ?string
{
if (count($node->children) !== 1) {
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 getLinenoOfAncestorReference
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getLinenoOfAncestorReference(FullyQualifiedClassName $fqsen): int
{
$class_line = $this->getFileRef()->getLineNumberStart();
foreach ($this->interface_fqsen_list as $i => $interface_fqsen) {
if ($interface_fqsen === $fqsen) {
- 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 emitWrongInheritanceCategoryWarning
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function emitWrongInheritanceCategoryWarning(
CodeBase $code_base,
Clazz $ancestor,
string $expected_inheritance_category,
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
The method fromReflectionClass() has an NPath complexity of 96000. The configured NPath complexity threshold is 200. Open
public static function fromReflectionClass(
CodeBase $code_base,
ReflectionClass $class
): Clazz {
// Build a set of flags based on the constitution
- 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 addMethod() has 122 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function addMethod(
CodeBase $code_base,
Method $method,
Option $type_option
): void {
- Exclude checks
The method toStubSignature() has an NPath complexity of 576. The configured NPath complexity threshold is 200. Open
private function toStubSignature(CodeBase $code_base): string
{
$string = '';
if ($this->isFinal()) {
- 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 addMethod() has an NPath complexity of 3996. The configured NPath complexity threshold is 200. Open
public function addMethod(
CodeBase $code_base,
Method $method,
Option $type_option
): void {
- 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 Clazz has 3605 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- Exclude checks
The method importMixin() has an NPath complexity of 273. The configured NPath complexity threshold is 200. Open
private function importMixin(CodeBase $code_base, Type $type): void
{
$fqsen = FullyQualifiedClassName::fromType($type);
if (!$code_base->hasClassWithFQSEN($fqsen) || $fqsen === $this->fqsen) {
Issue::maybeEmit(
- 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 adaptInheritedMethodFromTrait() has an NPath complexity of 300. The configured NPath complexity threshold is 200. Open
private function adaptInheritedMethodFromTrait(Method $method): Method
{
$method_flags = $method->getFlags();
if (Flags::bitVectorHasState($method_flags, \ast\flags\MODIFIER_PRIVATE)) {
$method = $method->createUseAlias($this, $method->getName(), \ast\flags\MODIFIER_PRIVATE);
- 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 getPropertyByNameInContext() has 171 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getPropertyByNameInContext(
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
- Exclude checks
The method importAncestorClass() has an NPath complexity of 1512. The configured NPath complexity threshold is 200. Open
public function importAncestorClass(
CodeBase $code_base,
Clazz $class,
Option $type_option
): void {
- 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 getPropertyByNameInContext() has an NPath complexity of 4480. The configured NPath complexity threshold is 200. Open
public function getPropertyByNameInContext(
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
- 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 fromReflectionClass() has 226 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function fromReflectionClass(
CodeBase $code_base,
ReflectionClass $class
): Clazz {
// Build a set of flags based on the constitution
- Exclude checks
The method addMethod() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function addMethod(
CodeBase $code_base,
Method $method,
Option $type_option
): void {
- 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 toStubSignature() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
private function toStubSignature(CodeBase $code_base): string
{
$string = '';
if ($this->isFinal()) {
- 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 checkPropertyCompatibility() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
private static function checkPropertyCompatibility(
CodeBase $code_base,
Property $inherited_property,
Property $overriding_property
): void {
- 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 importAncestorClass() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public function importAncestorClass(
CodeBase $code_base,
Clazz $class,
Option $type_option
): void {
- 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 getPropertyByNameInContext() has a Cyclomatic Complexity of 24. The configured cyclomatic complexity threshold is 10. Open
public function getPropertyByNameInContext(
CodeBase $code_base,
string $name,
Context $context,
bool $is_static,
- 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 fromReflectionClass() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10. Open
public static function fromReflectionClass(
CodeBase $code_base,
ReflectionClass $class
): Clazz {
// Build a set of flags based on the constitution
- 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 adaptInheritedMethodFromTrait() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
private function adaptInheritedMethodFromTrait(Method $method): Method
{
$method_flags = $method->getFlags();
if (Flags::bitVectorHasState($method_flags, \ast\flags\MODIFIER_PRIVATE)) {
$method = $method->createUseAlias($this, $method->getName(), \ast\flags\MODIFIER_PRIVATE);
- 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 importMixin() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
private function importMixin(CodeBase $code_base, Type $type): void
{
$fqsen = FullyQualifiedClassName::fromType($type);
if (!$code_base->hasClassWithFQSEN($fqsen) || $fqsen === $this->fqsen) {
Issue::maybeEmit(
- 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 Clazz has a coupling between objects value of 51. Consider to reduce the number of dependencies under 13. Open
class Clazz extends AddressableElement
{
use Memoize;
use ClosedScopeElement;
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($parameter_list as $i => $parameter) {
$old_type = $parameter->getNonVariadicUnionType();
$type = $old_type->withSelfResolvedInContext($context);
if ($type->hasStaticType()) {
$type = $type->withType($this->getFQSEN()->asType());
- 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 106.
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
foreach ($real_parameter_list as $i => $parameter) {
$old_type = $parameter->getNonVariadicUnionType();
$type = $old_type->withSelfResolvedInContext($context);
if ($type->hasStaticType()) {
$type = $type->withType($this->getFQSEN()->asType());
- 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 106.
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
private static function analyzeClassConstantOverrides(CodeBase $code_base, array $original_declared_class_constants): void
{
foreach ($original_declared_class_constants as $constant) {
if ($constant->isOverrideIntended() && !$constant->isOverride()) {
if ($constant->checkHasSuppressIssueAndIncrementCount(Issue::CommentOverrideOnNonOverrideConstant)) {
- 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 96.
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
private static function analyzePropertyOverrides(CodeBase $code_base, array $original_declared_properties): void
{
foreach ($original_declared_properties as $property) {
if ($property->isOverrideIntended() && !$property->isOverride()) {
if ($property->checkHasSuppressIssueAndIncrementCount(Issue::CommentOverrideOnNonOverrideProperty)) {
- 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 96.
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
foreach ($this->trait_fqsen_list as $i => $fqsen) {
if (!$code_base->hasClassWithFQSEN($fqsen)) {
continue;
}
- 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 94.
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
foreach ($this->interface_fqsen_list as $i => $fqsen) {
if (!$code_base->hasClassWithFQSEN($fqsen)) {
continue;
}
- 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 94.
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
private function getParentClassWithoutHydrating(CodeBase $code_base): Clazz
{
if (!$this->parent_type) {
throw new LogicException("Class $this has no parent");
}
- 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
public function getParentClass(CodeBase $code_base): Clazz
{
if (!$this->parent_type) {
throw new LogicException("Class $this has no parent");
}
- 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 $id. Configured minimum length is 3. Open
public function setDeclId(int $id): 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;
}
}
}