1.2.325. DI Cyclic Dependencies¶
When injecting dependencies, classes that mutually depend on each other is a code smell.
Dependency injection should be organized as an acyclic tree-like structure
<?php
// Classes A and B depends on each other.
class A {
protected $b;
public function __construct(B $b) {
$this->b = $b;
}
}
class B {
public $a;
protected function setA(A $a) {
$this->a = $a;
}
}
?>
See also Dependency Injection Smells.
1.2.325.1. Connex PHP features¶
1.2.325.1.1. Specs¶
Short name |
Classes/TypehintCyclicDependencies |
Rulesets |
|
Exakat since |
0.11.6 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |