1.2.1214. Too Many Injections¶
When a class is constructed with more than four dependencies, it should be split into smaller classes.
<?php
// This class relies on 5 other instances.
// It is probably doing too much.
class Foo {
public function __construct(
A $a,
B $b,
C $c,
D $d
E $e ) {
$this->a = $a;
$this->b = $b;
$this->d = $d;
$this->d = $d;
$this->e = $e;
}
}
?>
Name |
Default |
Type |
Description |
injectionsCount |
5 |
integer |
Threshold for too many injected parameters for one class. |
See also Dependency Injection Smells.
1.2.1214.1. Connex PHP features¶
1.2.1214.1.1. Suggestions¶
Split the class into smaller classes. Try to do less in that class.
1.2.1214.1.2. Specs¶
Short name |
Classes/TooManyInjections |
Rulesets |
|
Exakat since |
0.11.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Examples |
|
Available in |