src/Phan/Language/Context.php

Summary

Maintainability
F
3 days
Test Coverage

File Context.php has 569 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Phan\Language;
Severity: Major
Found in src/Phan/Language/Context.php - About 1 day to fix

    Context has 53 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Context extends FileRef
    {
        /**
         * @var string
         * The namespace of the file.
    Severity: Major
    Found in src/Phan/Language/Context.php - About 7 hrs to fix

      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.
      Severity: Minor
      Found in src/Phan/Language/Context.php by phpmd

      Method getNamespaceMapFor has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getNamespaceMapFor(
              int $flags,
              string $name
          ): FullyQualifiedGlobalStructuralElement {
      
      
      Severity: Minor
      Found in src/Phan/Language/Context.php - About 1 hr to fix

        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;
                }
        Severity: Minor
        Found in src/Phan/Language/Context.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

        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)) {
        Severity: Minor
        Found in src/Phan/Language/Context.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

        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) {
        Severity: Minor
        Found in src/Phan/Language/Context.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

        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) {
        Severity: Minor
        Found in src/Phan/Language/Context.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

        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.
        Severity: Minor
        Found in src/Phan/Language/Context.php by phpmd

        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) {
        Severity: Minor
        Found in src/Phan/Language/Context.php - About 1 hr to fix

          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,
          Severity: Minor
          Found in src/Phan/Language/Context.php - About 45 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

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

                  int $flags,
                  string $alias,
                  FullyQualifiedGlobalStructuralElement $target,
                  int $lineno,
                  CodeBase $code_base = null
          Severity: Minor
          Found in src/Phan/Language/Context.php - About 35 mins to fix

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

              Function getNamespaceMapFor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getNamespaceMapFor(
                      int $flags,
                      string $name
                  ): FullyQualifiedGlobalStructuralElement {
              
              
              Severity: Minor
              Found in src/Phan/Language/Context.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 $result;
              Severity: Major
              Found in src/Phan/Language/Context.php - About 30 mins to fix

                Function getFunctionLikeInScope has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getFunctionLikeInScope(
                        CodeBase $code_base
                    ): FunctionInterface {
                        $fqsen = $this->getFunctionLikeFQSEN();
                
                
                Severity: Minor
                Found in src/Phan/Language/Context.php - About 25 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

                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.
                Severity: Minor
                Found in src/Phan/Language/Context.php by phpmd

                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

                There are no issues that match your filters.

                Category
                Status