Skip to content

Commit f046f24

Browse files
authored
Generic types for DI classes (#20354)
1 parent 7037fd4 commit f046f24

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

framework/di/Container.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@ class Container extends Component
158158
* @throws InvalidConfigException if the class cannot be recognized or correspond to an invalid definition
159159
* @throws NotInstantiableException If resolved to an abstract class or an interface (since 2.0.9)
160160
*
161-
*
162-
* @template T of class-string
163-
* @psalm-param class-string<T>|array{class: class-string<T>} $class
164-
* @phpstan-param class-string<T>|array{class: class-string<T>} $class
165-
* @psalm-return T
166-
* @phpstan-return T
161+
* @template T of object
162+
* @psalm-param string|class-string<T>|Instance $class
163+
* @phpstan-param string|class-string<T>|Instance $class
164+
* @psalm-return ($class is class-string<T> ? T : object)
165+
* @phpstan-return ($class is class-string<T> ? T : object)
167166
*/
168167
public function get($class, $params = [], $config = [])
169168
{

framework/di/Instance.php

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public static function of($id, $optional = false)
114114
* @param ServiceLocator|Container|null $container the container. This will be passed to [[get()]].
115115
* @return object the object referenced by the Instance, or `$reference` itself if it is an object.
116116
* @throws InvalidConfigException if the reference is invalid
117+
*
118+
* @template T of object
119+
* @psalm-param class-string<T>|null $type
120+
* @phpstan-param class-string<T>|null $type
121+
* @psalm-return ($type is null ? object : T)
122+
* @phpstan-return ($type is null ? object : T)
117123
*/
118124
public static function ensure($reference, $type = null, $container = null)
119125
{

0 commit comments

Comments
 (0)