rspec/rules/S2830/rule.adoc

31 lines
788 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:48:07 +02:00
Dependency injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the dependency inversion and single responsibility principles.
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:07 +02:00
----
class SomeClass {
public function __construct() {
$this->object = new SomeOtherClass(); // Noncompliant
}
}
----
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:07 +02:00
----
class SomeClass {
public function __construct(SomeOtherClass $object) {
$this->object = $object;
}
}
----