Skip to content

Commit 6238940

Browse files
authored
Fix #20651: Add missing generics in yii\filters namespace
1 parent ed9af8a commit 6238940

File tree

13 files changed

+76
-21
lines changed

13 files changed

+76
-21
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+
- Bug #20651: Add missing generics in `yii\filters` namespace (mspirkov)
7677

7778

7879
2.0.53 June 27, 2025

framework/base/Action.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class Action extends Component
6262
* @param Controller $controller the controller that owns this action
6363
* @param array $config name-value pairs that will be used to initialize the object properties
6464
*
65+
* @phpstan-param T $controller
66+
* @psalm-param T $controller
67+
*
6568
* @phpstan-param array<string, mixed> $config
6669
* @psalm-param array<string, mixed> $config
6770
*/

framework/base/ActionFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public function afterFilter($event)
9898
* You may override this method to do last-minute preparation for the action.
9999
* @param Action $action the action to be executed.
100100
* @return bool whether the action should continue to be executed.
101+
*
102+
* @phpstan-param Action<Controller> $action
103+
* @psalm-param Action<Controller> $action
101104
*/
102105
public function beforeAction($action)
103106
{

framework/filters/AccessControl.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace yii\filters;
99

1010
use Yii;
11-
use yii\base\Action;
1211
use yii\base\ActionFilter;
1312
use yii\di\Instance;
1413
use yii\web\ForbiddenHttpException;
14+
use yii\web\IdentityInterface;
1515
use yii\web\User;
1616

1717
/**
@@ -60,6 +60,9 @@ class AccessControl extends ActionFilter
6060
* @var User|array|string|false the user object representing the authentication status or the ID of the user application component.
6161
* Starting from version 2.0.2, this can also be a configuration array for creating the object.
6262
* Starting from version 2.0.12, you can set it to `false` to explicitly switch this component support off for the filter.
63+
*
64+
* @phpstan-var User<IdentityInterface>|array|string|false
65+
* @psalm-var User<IdentityInterface>|array|string|false
6366
*/
6467
public $user = 'user';
6568
/**
@@ -109,10 +112,7 @@ public function init()
109112
}
110113

111114
/**
112-
* This method is invoked right before an action is to be executed (after all possible filters.)
113-
* You may override this method to do last-minute preparation for the action.
114-
* @param Action $action the action to be executed.
115-
* @return bool whether the action should continue to be executed.
115+
* {@inheritdoc}
116116
*/
117117
public function beforeAction($action)
118118
{
@@ -149,6 +149,9 @@ public function beforeAction($action)
149149
* if the user is already logged, a 403 HTTP exception will be thrown.
150150
* @param User|false $user the current user or boolean `false` in case of detached User component
151151
* @throws ForbiddenHttpException if the user is already logged in or in case of detached User component.
152+
*
153+
* @phpstan-param User<IdentityInterface>|false $user
154+
* @psalm-param User<IdentityInterface>|false $user
152155
*/
153156
protected function denyAccess($user)
154157
{

framework/filters/AccessRule.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use yii\base\InvalidConfigException;
1515
use yii\helpers\IpHelper;
1616
use yii\helpers\StringHelper;
17+
use yii\web\IdentityInterface;
1718
use yii\web\Request;
1819
use yii\web\User;
1920

@@ -166,6 +167,12 @@ class AccessRule extends Component
166167
* @param User|false $user the user object or `false` in case of detached User component
167168
* @param Request $request
168169
* @return bool|null `true` if the user is allowed, `false` if the user is denied, `null` if the rule does not apply to the user
170+
*
171+
* @phpstan-param Action<Controller> $action
172+
* @psalm-param Action<Controller> $action
173+
*
174+
* @phpstan-param User<IdentityInterface>|false $user
175+
* @psalm-param User<IdentityInterface>|false $user
169176
*/
170177
public function allows($action, $user, $request)
171178
{
@@ -186,6 +193,9 @@ public function allows($action, $user, $request)
186193
/**
187194
* @param Action $action the action
188195
* @return bool whether the rule applies to the action
196+
*
197+
* @phpstan-param Action<Controller> $action
198+
* @psalm-param Action<Controller> $action
189199
*/
190200
protected function matchAction($action)
191201
{
@@ -216,6 +226,9 @@ protected function matchController($controller)
216226
* @param User $user the user object
217227
* @return bool whether the rule applies to the role
218228
* @throws InvalidConfigException if User component is detached
229+
*
230+
* @phpstan-param User<IdentityInterface> $user
231+
* @psalm-param User<IdentityInterface> $user
219232
*/
220233
protected function matchRole($user)
221234
{
@@ -297,6 +310,9 @@ protected function matchVerb($verb)
297310
/**
298311
* @param Action $action the action to be performed
299312
* @return bool whether the rule should be applied
313+
*
314+
* @phpstan-param Action<Controller> $action
315+
* @psalm-param Action<Controller> $action
300316
*/
301317
protected function matchCustom($action)
302318
{

framework/filters/Cors.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace yii\filters;
99

1010
use Yii;
11+
use yii\base\Action;
1112
use yii\base\ActionFilter;
13+
use yii\base\Controller;
1214
use yii\base\InvalidConfigException;
1315
use yii\web\Request;
1416
use yii\web\Response;
@@ -119,7 +121,10 @@ public function beforeAction($action)
119121

120122
/**
121123
* Override settings for specific action.
122-
* @param \yii\base\Action $action the action settings to override
124+
* @param Action $action the action settings to override
125+
*
126+
* @phpstan-param Action<Controller> $action
127+
* @psalm-param Action<Controller> $action
123128
*/
124129
public function overrideDefaultSettings($action)
125130
{

framework/filters/HostControl.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace yii\filters;
99

1010
use Yii;
11+
use yii\base\Action;
1112
use yii\base\ActionFilter;
13+
use yii\base\Controller;
1214
use yii\helpers\StringHelper;
1315
use yii\web\NotFoundHttpException;
1416

@@ -160,8 +162,11 @@ public function beforeAction($action)
160162
* The default implementation will display 404 page right away, terminating the program execution.
161163
* You may override this method, creating your own deny access handler. While doing so, make sure you
162164
* avoid usage of the current requested host name, creation of absolute URL links, caching page parts and so on.
163-
* @param \yii\base\Action $action the action to be executed.
165+
* @param Action $action the action to be executed.
164166
* @throws NotFoundHttpException
167+
*
168+
* @phpstan-param Action<Controller> $action
169+
* @psalm-param Action<Controller> $action
165170
*/
166171
protected function denyAccess($action)
167172
{

framework/filters/HttpCache.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace yii\filters;
99

1010
use Yii;
11-
use yii\base\Action;
1211
use yii\base\ActionFilter;
1312

1413
/**
@@ -108,10 +107,7 @@ class HttpCache extends ActionFilter
108107

109108

110109
/**
111-
* This method is invoked right before an action is to be executed (after all possible filters.)
112-
* You may override this method to do last-minute preparation for the action.
113-
* @param Action $action the action to be executed.
114-
* @return bool whether the action should continue to be executed.
110+
* {@inheritdoc}
115111
*/
116112
public function beforeAction($action)
117113
{

framework/filters/PageCache.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Closure;
1111
use Yii;
12-
use yii\base\Action;
1312
use yii\base\ActionFilter;
1413
use yii\base\DynamicContentAwareInterface;
1514
use yii\base\DynamicContentAwareTrait;
@@ -163,10 +162,7 @@ public function init()
163162
}
164163

165164
/**
166-
* This method is invoked right before an action is to be executed (after all possible filters.)
167-
* You may override this method to do last-minute preparation for the action.
168-
* @param Action $action the action to be executed.
169-
* @return bool whether the action should continue to be executed.
165+
* {@inheritdoc}
170166
*/
171167
public function beforeAction($action)
172168
{

framework/filters/RateLimitInterface.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace yii\filters;
99

10+
use yii\base\Action;
11+
use yii\base\Controller;
12+
1013
/**
1114
* RateLimitInterface is the interface that may be implemented by an identity object to enforce rate limiting.
1215
*
@@ -18,27 +21,36 @@ interface RateLimitInterface
1821
/**
1922
* Returns the maximum number of allowed requests and the window size.
2023
* @param \yii\web\Request $request the current request
21-
* @param \yii\base\Action $action the action to be executed
24+
* @param Action $action the action to be executed
2225
* @return array an array of two elements. The first element is the maximum number of allowed requests,
2326
* and the second element is the size of the window in seconds.
27+
*
28+
* @phpstan-param Action<Controller> $action
29+
* @psalm-param Action<Controller> $action
2430
*/
2531
public function getRateLimit($request, $action);
2632

2733
/**
2834
* Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
2935
* @param \yii\web\Request $request the current request
30-
* @param \yii\base\Action $action the action to be executed
36+
* @param Action $action the action to be executed
3137
* @return array an array of two elements. The first element is the number of allowed requests,
3238
* and the second element is the corresponding UNIX timestamp.
39+
*
40+
* @phpstan-param Action<Controller> $action
41+
* @psalm-param Action<Controller> $action
3342
*/
3443
public function loadAllowance($request, $action);
3544

3645
/**
3746
* Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
3847
* @param \yii\web\Request $request the current request
39-
* @param \yii\base\Action $action the action to be executed
48+
* @param Action $action the action to be executed
4049
* @param int $allowance the number of allowed requests remaining.
4150
* @param int $timestamp the current timestamp.
51+
*
52+
* @phpstan-param Action<Controller> $action
53+
* @psalm-param Action<Controller> $action
4254
*/
4355
public function saveAllowance($request, $action, $allowance, $timestamp);
4456
}

0 commit comments

Comments
 (0)