Skip to content

Commit 66d9db1

Browse files
authored
Fix #20650: Add PHPStan/Psalm annotations for yii\di\Container
1 parent 5dcf4b8 commit 66d9db1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Yii Framework 2 Change Log
7373
- Bug #20639: Add missing generics in `yii\web` namespace (mspirkov)
7474
- Bug #20645: Add missing generics in `yii\helpers` and `yii\test` namespaces. Fix PHPDoc annotations in `ArrayAccessTrait` (mspirkov)
7575
- Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov)
76+
- Enh #20650: Add PHPStan/Psalm annotations for `yii\di\Container` (mspirkov)
7677
- Bug #20654: Add missing generics in `yii\db` namespace. Fix PHPDoc annotations in `yii\db\ArrayExpression` (mspirkov)
7778
- Bug #20651: Add missing generics in `yii\filters` namespace (mspirkov)
7879

framework/di/Container.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class Container extends Component
124124
/**
125125
* @var array cached dependencies indexed by class/interface names. Each class name
126126
* is associated with a list of constructor parameter types or default values.
127+
*
128+
* @phpstan-var array<class-string, array<string, mixed>>
127129
*/
128130
private $_dependencies = [];
129131
/**
@@ -386,10 +388,21 @@ public function getDefinitions()
386388
* @param array $config configurations to be applied to the new instance
387389
* @return object the newly created instance of the specified class
388390
* @throws NotInstantiableException If resolved to an abstract class or an interface (since 2.0.9)
391+
*
392+
* @template T of object
393+
*
394+
* @phpstan-param class-string<T> $class
395+
* @psalm-param class-string<T> $class
396+
*
397+
* @phpstan-return T
398+
* @psalm-return T
389399
*/
390400
protected function build($class, $params, $config)
391401
{
392-
/** @var ReflectionClass $reflection */
402+
/**
403+
* @var ReflectionClass $reflection
404+
* @phpstan-var ReflectionClass<T> $reflection
405+
*/
393406
list($reflection, $dependencies) = $this->getDependencies($class);
394407

395408
$addDependencies = [];
@@ -503,6 +516,14 @@ protected function mergeParams($class, $params)
503516
* @param string $class class name, interface name or alias name
504517
* @return array the dependencies of the specified class.
505518
* @throws NotInstantiableException if a dependency cannot be resolved or if a dependency cannot be fulfilled.
519+
*
520+
* @template T of object
521+
*
522+
* @phpstan-param class-string<T> $class
523+
* @psalm-param class-string<T> $class
524+
*
525+
* @phpstan-return array{ReflectionClass<T>, array<string, mixed>}
526+
* @psalm-return array{ReflectionClass<T>, array<string, mixed>}
506527
*/
507528
protected function getDependencies($class)
508529
{
@@ -590,6 +611,9 @@ private function isNulledParam($param)
590611
* @param ReflectionClass|null $reflection the class reflection associated with the dependencies
591612
* @return array the resolved dependencies
592613
* @throws InvalidConfigException if a dependency cannot be resolved or if a dependency cannot be fulfilled.
614+
*
615+
* @phpstan-param ReflectionClass<object>|null $reflection
616+
* @psalm-param ReflectionClass<object>|null $reflection
593617
*/
594618
protected function resolveDependencies($dependencies, $reflection = null)
595619
{

0 commit comments

Comments
 (0)