ClassElement
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class ClassElement extends AddressableElement
{
/** @var FullyQualifiedClassName the FQSEN of the class this ClassElement belongs to */
private $class_fqsen;
Function isAccessibleFromClass
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function isAccessibleFromClass(CodeBase $code_base, ?FullyQualifiedClassName $accessing_class_fqsen): bool
{
if ($this->isPublic()) {
return 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
Method isAccessibleFromClass
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function isAccessibleFromClass(CodeBase $code_base, ?FullyQualifiedClassName $accessing_class_fqsen): bool
{
if ($this->isPublic()) {
return true;
}
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Context $context,
string $name,
UnionType $type,
int $flags,
FullyQualifiedClassElement $fqsen
Function checkCanAccessProtectedElement
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function checkCanAccessProtectedElement(CodeBase $code_base, FullyQualifiedClassName $defining_fqsen, FullyQualifiedClassName $accessing_class_fqsen): bool
{
$accessing_class_type = $accessing_class_fqsen->asType();
$type_of_class_of_property = $defining_fqsen->asType();
- 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 false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return self::checkCanAccessProtectedElement($code_base, $defining_fqsen, $accessing_class_fqsen);
Avoid using empty try-catch blocks in checkCanAccessProtectedElement. Open
} catch (RecursionDepthException $_) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}