laminas / laminas-di

Automated dependency injection for PSR-11 containers
https://docs.laminas.dev/laminas-di/
BSD 3-Clause "New" or "Revised" License
36 stars 20 forks source link

[Fix] DEFAULT CONTAINER: Documentation & resolved phpstan-baseline error #58

Closed sjokkateer closed 2 years ago

sjokkateer commented 2 years ago
Q A
Documentation yes
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

This PR updates the type declaration (docblock) of the DefaultContainer::$services to the more specific array<string, object> and removes the resolved phpstan-baseline error. This type is derived as follows: within the DefaultContainer::__construct(), the keys are represented by class-string and mapped to values of type object. Additionally, DefaultContainer::setInstance() uses string type for keys and parameter $service is documented as type object, meaning that only type object occurs as value in DefaultContainer::$services.

As a logical consequence, DefaultContainer::get() returns objects based on the aforementioned, and InjectorInterface::create() which is also said to return type object. Although the DefaultContainer::get() is inherit from the ContainerInterface::class which has return type mixed, the child is allowed to have a more specific return type based on covariance.