1.2.280. Could Inject Parameter¶
The parameter is immediately used to create an object. It could be interesting to replace it with an injection of that object’s type to keep the method generic.
<?php
class x {
// The directory is immediately injected
function foo(Directory $dir) {
$this->dir = $dir;
}
// Path is injected, then turned into a directory
function bar(string $path) {
$this->dir = new Directory($path);
}
}
?>
1.2.280.1. Connex PHP features¶
1.2.280.1.1. Suggestions¶
Use the instantiation as the type of the parameter.
1.2.280.1.2. Specs¶
Short name |
Classes/CouldInjectParam |
Rulesets |
|
Exakat since |
2.4.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |