# yiisoft/yii2

framework/di/Container.php

### Summary

D
2 days

#### Function resolveCallableDependencies has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open

    public function resolveCallableDependencies(callable $callback,$params = [])
{
if (is_array($callback)) {$reflection = new \ReflectionMethod($callback[0],$callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
Found in framework/di/Container.php - About 7 hrs 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"

    protected function getDependencies($class) { if (isset($this->_reflections[$class])) { return [$this->_reflections[$class],$this->_dependencies[$class]]; } Found in framework/di/Container.php - About 6 hrs 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 an overall complexity of 123 which is very high. The configured complexity threshold is 50. Open class Container extends Component { /** * @var array singleton objects indexed by their types */ Found in framework/di/Container.php by phpmd #### Function normalizeDefinition has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open  protected function normalizeDefinition($class, $definition) { if (empty($definition)) {
return ['class' => $class]; } elseif (is_string($definition)) {
Found in framework/di/Container.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"

#### Function validateDependencies has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open

    private function validateDependencies($parameters) {$hasStringParameter = false;
$hasIntParameter = false; foreach ($parameters as $index =>$parameter) {
Found in framework/di/Container.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"

#### Function get has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open

    public function get($class,$params = [], $config = []) { if ($class instanceof Instance) {
$class =$class->id;
}
Found in framework/di/Container.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"

#### Consider simplifying this complex logical expression. Open

                if ($associative && isset($params[$name]) &&$params[$name] instanceof$className) {
{
/* @var $reflection ReflectionClass */ list($reflection, $dependencies) =$this->getDependencies($class);  Found in framework/di/Container.php - About 55 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 #### Function resolveDependencies has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open  protected function resolveDependencies($dependencies, $reflection = null) { foreach ($dependencies as $index =>$dependency) {
if ($dependency instanceof Instance) { if ($dependency->id !== null) {
Found in framework/di/Container.php - About 55 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"

            return $definition; Found in framework/di/Container.php - About 30 mins to fix #### The method getDependencies() has an NPath complexity of 728. The configured NPath complexity threshold is 200. Open  protected function getDependencies($class)
{
if (isset($this->_reflections[$class])) {
return [$this->_reflections[$class], $this->_dependencies[$class]];
}
Found in framework/di/Container.php by phpmd

## 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 build() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open

    protected function build($class,$params, $config) { /* @var$reflection ReflectionClass */
list($reflection,$dependencies) = $this->getDependencies($class);


Found in framework/di/Container.php by phpmd

## 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 resolveCallableDependencies() has an NPath complexity of 2416. The configured NPath complexity threshold is 200. Open

    public function resolveCallableDependencies(callable $callback,$params = [])
{
if (is_array($callback)) {$reflection = new \ReflectionMethod($callback[0],$callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
Found in framework/di/Container.php by phpmd

## 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 normalizeDefinition() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open

    protected function normalizeDefinition($class,$definition)
{
if (empty($definition)) { return ['class' =>$class];
} elseif (is_string($definition)) { Found in framework/di/Container.php by phpmd ## 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 resolveCallableDependencies() has a Cyclomatic Complexity of 33. The configured cyclomatic complexity threshold is 10. Open

    public function resolveCallableDependencies(callable $callback,$params = [])
{
if (is_array($callback)) {$reflection = new \ReflectionMethod($callback[0],$callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
Found in framework/di/Container.php by phpmd

## 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 {
{
/* @var $reflection ReflectionClass */ list($reflection, $dependencies) =$this->getDependencies($class);  Found in framework/di/Container.php by phpmd ## 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;
}
}
}
}

    protected function getDependencies($class) { if (isset($this->_reflections[$class])) { return [$this->_reflections[$class],$this->_dependencies[$class]]; } Found in framework/di/Container.php by phpmd ## 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 Container has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open

class Container extends Component
{
/**
* @var array singleton objects indexed by their types
*/
Found in framework/di/Container.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 #### Missing class import via use statement (line '652', column '31'). Open $reflection = new \ReflectionMethod($callback[0],$callback[1]);
Found in framework/di/Container.php by phpmd

## MissingImport

### Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

## Example

function make() {
return new \stdClass();
}

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

#### Missing class import via use statement (line '656', column '31'). Open

            $reflection = new \ReflectionFunction($callback);
Found in framework/di/Container.php by phpmd

## MissingImport

### Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

## Example

function make() {
return new \stdClass();
}

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

#### Missing class import via use statement (line '654', column '31'). Open

            $reflection = new \ReflectionMethod($callback, '__invoke');
Found in framework/di/Container.php by phpmd

## MissingImport

### Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

## Example

function make() {
return new \stdClass();
}

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

#### The method hasSingleton has a boolean flag argument $checkInstance, which is a certain sign of a Single Responsibility Principle violation. Open  public function hasSingleton($class, $checkInstance = false) Found in framework/di/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

#### Avoid assigning values to variables in if clauses and the like (line '698', column '73'). Open

    public function resolveCallableDependencies(callable $callback,$params = [])
{
if (is_array($callback)) {$reflection = new \ReflectionMethod($callback[0],$callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
Found in framework/di/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
// ...
}

        foreach ($parameters as$index => $parameter) { Found in framework/di/Container.php by phpmd ## UnusedLocalVariable ### Since: 0.2 Detects when a local variable is declared and/or assigned, but not used. ## Example class Foo { public function doSomething() {$i = 5; // Unused
}
}