Formula9/Framework

View on GitHub
Nine/Containers/Container.php

Summary

Maintainability
D
2 days
Test Coverage

File Container.php has 547 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php namespace Nine\Containers;

/**
 * **A Dependency Injection and Service Locator container.**
 *
Severity: Major
Found in Nine/Containers/Container.php - About 1 day to fix

    Container has 62 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Container implements ArrayAccess, ContainerContract
    {
        /**
         * The contextual binding map.
         *
    Severity: Major
    Found in Nine/Containers/Container.php - About 1 day to fix

      The class Container has an overall complexity of 136 which is very high. The configured complexity threshold is 50.
      Open

      class Container implements ArrayAccess, ContainerContract
      {
          /**
           * The contextual binding map.
           *
      Severity: Minor
      Found in Nine/Containers/Container.php by phpmd

      The class Container has 44 non-getter- and setter-methods. Consider refactoring Container to keep number of methods under 25.
      Open

      class Container implements ArrayAccess, ContainerContract
      {
          /**
           * The contextual binding map.
           *
      Severity: Minor
      Found in Nine/Containers/Container.php by phpmd

      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

      The class Container has 31 public methods. Consider refactoring Container to keep number of public methods under 10.
      Open

      class Container implements ArrayAccess, ContainerContract
      {
          /**
           * The contextual binding map.
           *
      Severity: Minor
      Found in Nine/Containers/Container.php by phpmd

      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

      Method build has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function build($concrete, array $parameters = [])
          {
              // If the concrete type is actually a Closure, we will just execute it and
              // hand back the results of the functions, which allows functions to be
              // used as resolvers for more fine-tuned resolution of these objects.
      Severity: Minor
      Found in Nine/Containers/Container.php - About 1 hr to fix

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

            public function build($concrete, array $parameters = [])
            {
                // If the concrete type is actually a Closure, we will just execute it and
                // hand back the results of the functions, which allows functions to be
                // used as resolvers for more fine-tuned resolution of these objects.
        Severity: Minor
        Found in Nine/Containers/Container.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 Container has 1312 lines of code. Current threshold is 1000. Avoid really long classes.
        Open

        class Container implements ArrayAccess, ContainerContract
        {
            /**
             * The contextual binding map.
             *
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        The method bindIf has a boolean flag argument $shared, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function bindIf($abstract, $concrete = NULL, $shared = FALSE)
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method bind has a boolean flag argument $shared, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function bind($abstract, $concrete = NULL, $shared = FALSE)
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method extend uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $this->extenders[$abstract][] = $closure;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        Avoid assigning values to variables in if clauses and the like (line '1304', column '25').
        Open

            protected function resolveNonClass(ReflectionParameter $parameter)
            {
                if ( ! NULL === $concrete = $this->getContextualConcrete('$' . $parameter->name)) {
                    if ($concrete instanceof Closure) {
                        return $concrete ($this);
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        The method resolving uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $this->resolvingCallbacks[$this->normalize($abstract)][] = $callback;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method getDependencies uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    else {
                        $dependencies[] = $this->resolveClass($parameter);
                    }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method build uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    else {
                        $message = "Target [$concrete] is not instantiable.";
                    }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method afterResolving uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $this->afterResolvingCallbacks[$this->normalize($abstract)][] = $callback;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        Avoid assigning values to variables in if clauses and the like (line '1050', column '25').
        Open

            protected function getConcrete($abstract)
            {
                if ( ! NULL === $concrete = $this->getContextualConcrete($abstract)) {
                    return $concrete;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        The method resolvingCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $this->globalResolvingCallbacks[] = $callback;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method afterResolvingCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $this->globalAfterResolvingCallbacks[] = $callback;
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method resolveNonClass uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    else {
                        return $concrete;
                    }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method make uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    $object = $this->make($concrete, $parameters);
                }
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        Avoid unused parameters such as '$app'.
        Open

                return $this->rebinding($this->normalize($abstract), function ($app, $instance) use ($target, $method) {
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

        Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

        Avoid excessively long variable names like $globalAfterResolvingCallbacks. Keep variable name length under 20.
        Open

            protected $globalAfterResolvingCallbacks = [];
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid excessively long variable names like $afterResolvingCallbacks. Keep variable name length under 20.
        Open

            protected $afterResolvingCallbacks = [];
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid excessively long variable names like $globalResolvingCallbacks. Keep variable name length under 20.
        Open

            protected $globalResolvingCallbacks = [];
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid variables with short names like $c. Configured minimum length is 3.
        Open

                return function ($c, $parameters = []) use ($abstract, $concrete) {
        Severity: Minor
        Found in Nine/Containers/Container.php by phpmd

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

        Source https://phpmd.org/rules/naming.html#shortvariable

        There are no issues that match your filters.

        Category
        Status