Skip to content

Commit c569e91

Browse files
authored
Fix #20666: Add missing generics in yii\base, yii\console, yii\filters and yii\web namespaces
1 parent 1821a61 commit c569e91

32 files changed

+189
-31
lines changed

build/controllers/PhpDocController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ protected function hasSetterInParents($className, $propName)
964964
* @param string $className
965965
* @param \ReflectionClass $ref
966966
* @return bool
967+
*
968+
* @phpstan-param \ReflectionClass<object> $ref
967969
*/
968970
protected function isBaseObject($className, \ReflectionClass $ref)
969971
{

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Yii Framework 2 Change Log
8080
- Bug #20659: Fix PHP `8.5` `null` array offset deprecation warnings in `MariaDB` driver (terabytesoftw)
8181
- Bug #20665: Fix PHP `8.5` `null` array offset deprecation warnings in `yii\build\controllers\ReleaseController` class (terabytesoftw)
8282
- Bug #20658: Add missing generics in `yii\console`, `yii\captcha`, `yii\caching` and `yii\behaviors` namespaces (mspirkov)
83+
- Bug #20666: Add missing generics in `yii\base`, `yii\console`, `yii\filters` and `yii\web` namespaces (mspirkov)
8384

8485

8586
2.0.53 June 27, 2025

framework/base/Action.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
* @since 2.0
3737
*
3838
* @template T of Controller
39-
*
40-
* @phpstan-property T $controller
41-
* @psalm-property T $controller
4239
*/
4340
class Action extends Component
4441
{

framework/base/ActionEvent.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
*
1515
* @author Qiang Xue <qiang.xue@gmail.com>
1616
* @since 2.0
17+
*
18+
* @template T of Action
1719
*/
1820
class ActionEvent extends Event
1921
{
2022
/**
2123
* @var Action the action currently being executed
24+
*
25+
* @phpstan-var T
26+
* @psalm-var T
2227
*/
2328
public $action;
2429
/**
@@ -38,6 +43,9 @@ class ActionEvent extends Event
3843
* @param Action $action the action associated with this action event.
3944
* @param array $config name-value pairs that will be used to initialize the object properties
4045
*
46+
* @phpstan-param T $action
47+
* @psalm-param T $action
48+
*
4149
* @phpstan-param array<string, mixed> $config
4250
* @psalm-param array<string, mixed> $config
4351
*/

framework/base/ActionFilter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
*
2222
* @author Qiang Xue <qiang.xue@gmail.com>
2323
* @since 2.0
24+
*
25+
* @template T of Component
26+
* @extends Behavior<T>
2427
*/
2528
class ActionFilter extends Behavior
2629
{
@@ -67,6 +70,9 @@ public function detach()
6770

6871
/**
6972
* @param ActionEvent $event
73+
*
74+
* @phpstan-param ActionEvent<Action<Controller>> $event
75+
* @psalm-param ActionEvent<Action<Controller>> $event
7076
*/
7177
public function beforeFilter($event)
7278
{
@@ -86,6 +92,9 @@ public function beforeFilter($event)
8692

8793
/**
8894
* @param ActionEvent $event
95+
*
96+
* @phpstan-param ActionEvent<Action<Controller>> $event
97+
* @psalm-param ActionEvent<Action<Controller>> $event
8998
*/
9099
public function afterFilter($event)
91100
{
@@ -113,6 +122,9 @@ public function beforeAction($action)
113122
* @param Action $action the action just executed.
114123
* @param mixed $result the action execution result
115124
* @return mixed the processed action result.
125+
*
126+
* @phpstan-param Action<Controller> $action
127+
* @psalm-param Action<Controller> $action
116128
*/
117129
public function afterAction($action, $result)
118130
{
@@ -124,6 +136,9 @@ public function afterAction($action, $result)
124136
* @param Action $action
125137
* @return string
126138
* @since 2.0.7
139+
*
140+
* @phpstan-param Action<Controller> $action
141+
* @psalm-param Action<Controller> $action
127142
*/
128143
protected function getActionId($action)
129144
{
@@ -144,6 +159,9 @@ protected function getActionId($action)
144159
* Returns a value indicating whether the filter is active for the given action.
145160
* @param Action $action the action being filtered
146161
* @return bool whether the filter is active for the given action.
162+
*
163+
* @phpstan-param Action<Controller> $action
164+
* @psalm-param Action<Controller> $action
147165
*/
148166
protected function isActive($action)
149167
{

framework/base/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ abstract class Application extends Module
127127
public $requestedRoute;
128128
/**
129129
* @var Action|null the requested Action. If null, it means the request cannot be resolved into an action.
130+
*
131+
* @phpstan-var Action<covariant Controller>|null
132+
* @psalm-var Action<covariant Controller>|null
130133
*/
131134
public $requestedAction;
132135
/**

framework/base/ArrayAccessTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ trait ArrayAccessTrait
2828
* This method is required by the SPL interface [[\IteratorAggregate]].
2929
* It will be implicitly called when you use `foreach` to traverse the collection.
3030
* @return \ArrayIterator an iterator for traversing the cookies in the collection.
31+
*
32+
* @phpstan-return \ArrayIterator<array-key, mixed>
33+
* @psalm-return \ArrayIterator<array-key, mixed>
3134
*/
3235
#[\ReturnTypeWillChange]
3336
public function getIterator()

framework/base/Behavior.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public function events()
7777
* and attach event handlers as declared in [[events]].
7878
* Make sure you call the parent implementation if you override this method.
7979
* @param Component $owner the component that this behavior is to be attached to.
80+
*
81+
* @phpstan-param T $owner
82+
* @psalm-param T $owner
8083
*/
8184
public function attach($owner)
8285
{

framework/base/Component.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
*
9898
* @author Qiang Xue <qiang.xue@gmail.com>
9999
* @since 2.0
100+
*
101+
* @phpstan-property-read Behavior<$this>[] $behaviors
102+
* @psalm-property-read Behavior<$this>[] $behaviors
100103
*/
101104
class Component extends BaseObject
102105
{
@@ -111,6 +114,8 @@ class Component extends BaseObject
111114
private $_eventWildcards = [];
112115
/**
113116
* @var Behavior[]|null the attached behaviors (behavior name => behavior). This is `null` when not initialized.
117+
*
118+
* @phpstan-var Behavior<$this>[]|null
114119
*/
115120
private $_behaviors;
116121

@@ -661,6 +666,9 @@ public function trigger($name, ?Event $event = null)
661666
* Returns the named behavior object.
662667
* @param string $name the behavior name
663668
* @return Behavior|null the behavior object, or null if the behavior does not exist
669+
*
670+
* @phpstan-return Behavior<$this>|null
671+
* @psalm-return Behavior<$this>|null
664672
*/
665673
public function getBehavior($name)
666674
{
@@ -671,6 +679,9 @@ public function getBehavior($name)
671679
/**
672680
* Returns all behaviors attached to this component.
673681
* @return Behavior[] list of behaviors attached to this component
682+
*
683+
* @phpstan-return Behavior<$this>[]
684+
* @psalm-return Behavior<$this>[]
674685
*/
675686
public function getBehaviors()
676687
{
@@ -692,6 +703,12 @@ public function getBehaviors()
692703
*
693704
* @return Behavior the behavior object
694705
* @see detachBehavior()
706+
*
707+
* @phpstan-param string|array|Behavior<$this> $behavior
708+
* @psalm-param string|array|Behavior<$this> $behavior
709+
*
710+
* @phpstan-return Behavior<$this>
711+
* @psalm-return Behavior<$this>
695712
*/
696713
public function attachBehavior($name, $behavior)
697714
{
@@ -719,6 +736,9 @@ public function attachBehaviors($behaviors)
719736
* The behavior's [[Behavior::detach()]] method will be invoked.
720737
* @param string $name the behavior's name.
721738
* @return Behavior|null the detached behavior. Null if the behavior does not exist.
739+
*
740+
* @phpstan-return Behavior<$this>|null
741+
* @psalm-return Behavior<$this>|null
722742
*/
723743
public function detachBehavior($name)
724744
{
@@ -764,6 +784,10 @@ public function ensureBehaviors()
764784
* will be detached first.
765785
* @param string|array|Behavior $behavior the behavior to be attached
766786
* @return Behavior the attached behavior.
787+
*
788+
* @phpstan-param string|array|Behavior<$this> $behavior
789+
*
790+
* @phpstan-return Behavior<$this>
767791
*/
768792
private function attachBehaviorInternal($name, $behavior)
769793
{

framework/base/Controller.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class Controller extends Component implements ViewContextInterface
6060
/**
6161
* @var Action|null the action that is currently being executed. This property will be set
6262
* by [[run()]] when it is called by [[Application]] to run an action.
63+
*
64+
* @phpstan-var Action<$this>|null
65+
* @psalm-var Action<$this>|null
6366
*/
6467
public $action;
6568
/**
@@ -234,8 +237,8 @@ public function run($route, $params = [])
234237
* @param array $params the parameters to be bound to the action.
235238
* @return array the valid parameters that the action can run with.
236239
*
237-
* @phpstan-param Action<static> $action
238-
* @psalm-param Action<static> $action
240+
* @phpstan-param Action<$this> $action
241+
* @psalm-param Action<$this> $action
239242
*
240243
* @phpstan-param array<array-key, mixed> $params
241244
* @psalm-param array<array-key, mixed> $params
@@ -257,6 +260,9 @@ public function bindActionParams($action, $params)
257260
* method will be created and returned.
258261
* @param string $id the action ID.
259262
* @return Action|null the newly created action instance. Null if the ID doesn't resolve into any action.
263+
*
264+
* @phpstan-return Action<$this>|null
265+
* @psalm-return Action<$this>|null
260266
*/
261267
public function createAction($id)
262268
{
@@ -312,8 +318,8 @@ public function createAction($id)
312318
* @param Action $action the action to be executed.
313319
* @return bool whether the action should continue to run.
314320
*
315-
* @phpstan-param Action<static> $action
316-
* @psalm-param Action<static> $action
321+
* @phpstan-param Action<$this> $action
322+
* @psalm-param Action<$this> $action
317323
*/
318324
public function beforeAction($action)
319325
{
@@ -343,8 +349,8 @@ public function beforeAction($action)
343349
* @param mixed $result the action return result.
344350
* @return mixed the processed action result.
345351
*
346-
* @phpstan-param Action<static> $action
347-
* @psalm-param Action<static> $action
352+
* @phpstan-param Action<$this> $action
353+
* @psalm-param Action<$this> $action
348354
*/
349355
public function afterAction($action, $result)
350356
{

0 commit comments

Comments
 (0)