src/Phan/Language/Element/ClassElement.php

Summary

Maintainability
C
7 hrs
Test Coverage

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;

Severity: Minor
Found in src/Phan/Language/Element/ClassElement.php - About 2 hrs to fix

    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;
            }
    Severity: Minor
    Found in src/Phan/Language/Element/ClassElement.php - About 1 hr to fix

    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;
            }
    Severity: Minor
    Found in src/Phan/Language/Element/ClassElement.php - About 1 hr to fix

      Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              Context $context,
              string $name,
              UnionType $type,
              int $flags,
              FullyQualifiedClassElement $fqsen
      Severity: Minor
      Found in src/Phan/Language/Element/ClassElement.php - About 35 mins to fix

        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();
        
        
        Severity: Minor
        Found in src/Phan/Language/Element/ClassElement.php - About 35 mins to fix

        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;
        Severity: Major
        Found in src/Phan/Language/Element/ClassElement.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                                  return true;
          Severity: Major
          Found in src/Phan/Language/Element/ClassElement.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return self::checkCanAccessProtectedElement($code_base, $defining_fqsen, $accessing_class_fqsen);
            Severity: Major
            Found in src/Phan/Language/Element/ClassElement.php - About 30 mins to fix

              Avoid using empty try-catch blocks in checkCanAccessProtectedElement.
              Open

                      } catch (RecursionDepthException $_) {
                      }

              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
                }
              }

              Source https://phpmd.org/rules/design.html#emptycatchblock

              There are no issues that match your filters.

              Category
              Status