Concrete dependency injection (ARCH7199)
Ce contenu n’est pas encore disponible dans votre langue.
Key php.quality.concrete-dependency · Severity info · Category quality
Typing dependencies as concrete classes violates the dependency inversion principle (DIP) and couples the class to a specific implementation. Depend on interfaces.
Incorrect
Section titled “Incorrect”<?phpclass ReportService{ public function __construct(private MySqlReportRepository $repo) {}}Correct
Section titled “Correct”<?phpclass ReportService{ public function __construct(private ReportRepository $repo) {}}Type constructor dependencies as interfaces/abstractions rather than concrete classes.