Fix #20666: Add missing generics in yii\base, yii\console, yii\filters and yii\web namespaces

This commit is contained in:
Maksim Spirkov
2025-10-31 22:43:14 +03:00
committed by GitHub
parent 1821a61ddc
commit c569e9136b
32 changed files with 189 additions and 31 deletions

View File

@@ -80,6 +80,7 @@ Yii Framework 2 Change Log
- Bug #20659: Fix PHP `8.5` `null` array offset deprecation warnings in `MariaDB` driver (terabytesoftw)
- Bug #20665: Fix PHP `8.5` `null` array offset deprecation warnings in `yii\build\controllers\ReleaseController` class (terabytesoftw)
- Bug #20658: Add missing generics in `yii\console`, `yii\captcha`, `yii\caching` and `yii\behaviors` namespaces (mspirkov)
- Bug #20666: Add missing generics in `yii\base`, `yii\console`, `yii\filters` and `yii\web` namespaces (mspirkov)
2.0.53 June 27, 2025

View File

@@ -36,9 +36,6 @@ use Yii;
* @since 2.0
*
* @template T of Controller
*
* @phpstan-property T $controller
* @psalm-property T $controller
*/
class Action extends Component
{

View File

@@ -14,11 +14,16 @@ namespace yii\base;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Action
*/
class ActionEvent extends Event
{
/**
* @var Action the action currently being executed
*
* @phpstan-var T
* @psalm-var T
*/
public $action;
/**
@@ -38,6 +43,9 @@ class ActionEvent extends Event
* @param Action $action the action associated with this action event.
* @param array $config name-value pairs that will be used to initialize the object properties
*
* @phpstan-param T $action
* @psalm-param T $action
*
* @phpstan-param array<string, mixed> $config
* @psalm-param array<string, mixed> $config
*/

View File

@@ -21,6 +21,9 @@ use yii\helpers\StringHelper;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends Behavior<T>
*/
class ActionFilter extends Behavior
{
@@ -67,6 +70,9 @@ class ActionFilter extends Behavior
/**
* @param ActionEvent $event
*
* @phpstan-param ActionEvent<Action<Controller>> $event
* @psalm-param ActionEvent<Action<Controller>> $event
*/
public function beforeFilter($event)
{
@@ -86,6 +92,9 @@ class ActionFilter extends Behavior
/**
* @param ActionEvent $event
*
* @phpstan-param ActionEvent<Action<Controller>> $event
* @psalm-param ActionEvent<Action<Controller>> $event
*/
public function afterFilter($event)
{
@@ -113,6 +122,9 @@ class ActionFilter extends Behavior
* @param Action $action the action just executed.
* @param mixed $result the action execution result
* @return mixed the processed action result.
*
* @phpstan-param Action<Controller> $action
* @psalm-param Action<Controller> $action
*/
public function afterAction($action, $result)
{
@@ -124,6 +136,9 @@ class ActionFilter extends Behavior
* @param Action $action
* @return string
* @since 2.0.7
*
* @phpstan-param Action<Controller> $action
* @psalm-param Action<Controller> $action
*/
protected function getActionId($action)
{
@@ -144,6 +159,9 @@ class ActionFilter extends Behavior
* Returns a value indicating whether the filter is active for the given action.
* @param Action $action the action being filtered
* @return bool whether the filter is active for the given action.
*
* @phpstan-param Action<Controller> $action
* @psalm-param Action<Controller> $action
*/
protected function isActive($action)
{

View File

@@ -127,6 +127,9 @@ abstract class Application extends Module
public $requestedRoute;
/**
* @var Action|null the requested Action. If null, it means the request cannot be resolved into an action.
*
* @phpstan-var Action<covariant Controller>|null
* @psalm-var Action<covariant Controller>|null
*/
public $requestedAction;
/**

View File

@@ -28,6 +28,9 @@ trait ArrayAccessTrait
* This method is required by the SPL interface [[\IteratorAggregate]].
* It will be implicitly called when you use `foreach` to traverse the collection.
* @return \ArrayIterator an iterator for traversing the cookies in the collection.
*
* @phpstan-return \ArrayIterator<array-key, mixed>
* @psalm-return \ArrayIterator<array-key, mixed>
*/
#[\ReturnTypeWillChange]
public function getIterator()

View File

@@ -77,6 +77,9 @@ class Behavior extends BaseObject
* and attach event handlers as declared in [[events]].
* Make sure you call the parent implementation if you override this method.
* @param Component $owner the component that this behavior is to be attached to.
*
* @phpstan-param T $owner
* @psalm-param T $owner
*/
public function attach($owner)
{

View File

@@ -97,6 +97,9 @@ use yii\helpers\StringHelper;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @phpstan-property-read Behavior<$this>[] $behaviors
* @psalm-property-read Behavior<$this>[] $behaviors
*/
class Component extends BaseObject
{
@@ -111,6 +114,8 @@ class Component extends BaseObject
private $_eventWildcards = [];
/**
* @var Behavior[]|null the attached behaviors (behavior name => behavior). This is `null` when not initialized.
*
* @phpstan-var Behavior<$this>[]|null
*/
private $_behaviors;
@@ -661,6 +666,9 @@ class Component extends BaseObject
* Returns the named behavior object.
* @param string $name the behavior name
* @return Behavior|null the behavior object, or null if the behavior does not exist
*
* @phpstan-return Behavior<$this>|null
* @psalm-return Behavior<$this>|null
*/
public function getBehavior($name)
{
@@ -671,6 +679,9 @@ class Component extends BaseObject
/**
* Returns all behaviors attached to this component.
* @return Behavior[] list of behaviors attached to this component
*
* @phpstan-return Behavior<$this>[]
* @psalm-return Behavior<$this>[]
*/
public function getBehaviors()
{
@@ -692,6 +703,12 @@ class Component extends BaseObject
*
* @return Behavior the behavior object
* @see detachBehavior()
*
* @phpstan-param string|array|Behavior<$this> $behavior
* @psalm-param string|array|Behavior<$this> $behavior
*
* @phpstan-return Behavior<$this>
* @psalm-return Behavior<$this>
*/
public function attachBehavior($name, $behavior)
{
@@ -719,6 +736,9 @@ class Component extends BaseObject
* The behavior's [[Behavior::detach()]] method will be invoked.
* @param string $name the behavior's name.
* @return Behavior|null the detached behavior. Null if the behavior does not exist.
*
* @phpstan-return Behavior<$this>|null
* @psalm-return Behavior<$this>|null
*/
public function detachBehavior($name)
{
@@ -764,6 +784,10 @@ class Component extends BaseObject
* will be detached first.
* @param string|array|Behavior $behavior the behavior to be attached
* @return Behavior the attached behavior.
*
* @phpstan-param string|array|Behavior<$this> $behavior
*
* @phpstan-return Behavior<$this>
*/
private function attachBehaviorInternal($name, $behavior)
{

View File

@@ -60,6 +60,9 @@ class Controller extends Component implements ViewContextInterface
/**
* @var Action|null the action that is currently being executed. This property will be set
* by [[run()]] when it is called by [[Application]] to run an action.
*
* @phpstan-var Action<$this>|null
* @psalm-var Action<$this>|null
*/
public $action;
/**
@@ -234,8 +237,8 @@ class Controller extends Component implements ViewContextInterface
* @param array $params the parameters to be bound to the action.
* @return array the valid parameters that the action can run with.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params
@@ -257,6 +260,9 @@ class Controller extends Component implements ViewContextInterface
* method will be created and returned.
* @param string $id the action ID.
* @return Action|null the newly created action instance. Null if the ID doesn't resolve into any action.
*
* @phpstan-return Action<$this>|null
* @psalm-return Action<$this>|null
*/
public function createAction($id)
{
@@ -312,8 +318,8 @@ class Controller extends Component implements ViewContextInterface
* @param Action $action the action to be executed.
* @return bool whether the action should continue to run.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function beforeAction($action)
{
@@ -343,8 +349,8 @@ class Controller extends Component implements ViewContextInterface
* @param mixed $result the action return result.
* @return mixed the processed action result.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function afterAction($action, $result)
{

View File

@@ -37,6 +37,9 @@ class InlineAction extends Action
* @param string $actionMethod the controller method that this inline action is associated with
* @param array $config name-value pairs that will be used to initialize the object properties
*
* @phpstan-param T $controller
* @psalm-param T $controller
*
* @phpstan-param array<string, mixed> $config
* @psalm-param array<string, mixed> $config
*/

View File

@@ -53,14 +53,14 @@ use yii\validators\Validator;
* ```
*
* Empty array if no errors.
* @property-read \yii\validators\Validator[] $activeValidators The validators applicable to the current
* @property-read Validator[] $activeValidators The validators applicable to the current
* [[scenario]].
* @property array $attributes Attribute values (name => value).
* @property-read array $firstErrors The first errors. The array keys are the attribute names, and the array
* values are the corresponding error messages. An empty array will be returned if there is no error.
* @property-read ArrayIterator $iterator An iterator for traversing the items in the list.
* @property string $scenario The scenario that this model is in. Defaults to [[SCENARIO_DEFAULT]].
* @property-read ArrayObject|\yii\validators\Validator[] $validators All the validators declared in the
* @property-read ArrayObject|Validator[] $validators All the validators declared in the
* model.
*
* @author Qiang Xue <qiang.xue@gmail.com>
@@ -74,6 +74,15 @@ use yii\validators\Validator;
*
* @phpstan-property-read array<string, string> $firstErrors
* @psalm-property-read array<string, string> $firstErrors
*
* @phpstan-property-read ArrayIterator<string, mixed> $iterator
* @psalm-property-read ArrayIterator<string, mixed> $iterator
*
* @phpstan-property-read ArrayObject<int, Validator>|Validator[] $validators
* @psalm-property-read ArrayObject<int, Validator>|Validator[] $validators
*
* @implements IteratorAggregate<string, mixed>
* @implements ArrayAccess<string, mixed>
*/
class Model extends Component implements StaticInstanceInterface, IteratorAggregate, ArrayAccess, Arrayable
{
@@ -100,6 +109,8 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
private $_errors;
/**
* @var ArrayObject|null list of validators
*
* @phpstan-var ArrayObject<int, Validator>|null
*/
private $_validators;
/**
@@ -447,7 +458,10 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
* $model->validators[] = $newValidator;
* ```
*
* @return ArrayObject|\yii\validators\Validator[] all the validators declared in the model.
* @return ArrayObject|Validator[] all the validators declared in the model.
*
* @phpstan-return ArrayObject<int, Validator>|Validator[]
* @psalm-return ArrayObject<int, Validator>|Validator[]
*/
public function getValidators()
{
@@ -462,7 +476,7 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
* Returns the validators applicable to the current [[scenario]].
* @param string|null $attribute the name of the attribute whose applicable validators should be returned.
* If this is null, the validators for ALL attributes in the model will be returned.
* @return \yii\validators\Validator[] the validators applicable to the current [[scenario]].
* @return Validator[] the validators applicable to the current [[scenario]].
*/
public function getActiveValidators($attribute = null)
{
@@ -492,6 +506,9 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
* Unlike [[getValidators()]], each time this method is called, a new list of validators will be returned.
* @return ArrayObject validators
* @throws InvalidConfigException if any validation rule configuration is invalid
*
* @phpstan-return ArrayObject<int, Validator>
* @psalm-return ArrayObject<int, Validator>
*/
public function createValidators()
{
@@ -1045,6 +1062,9 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
* Returns an iterator for traversing the attributes in the model.
* This method is required by the interface [[\IteratorAggregate]].
* @return ArrayIterator an iterator for traversing the items in the list.
*
* @phpstan-return ArrayIterator<string, mixed>
* @psalm-return ArrayIterator<string, mixed>
*/
#[\ReturnTypeWillChange]
public function getIterator()

View File

@@ -717,6 +717,9 @@ class Module extends ServiceLocator
*
* @param Action $action the action to be executed.
* @return bool whether the action should continue to be executed.
*
* @phpstan-param Action<Controller> $action
* @psalm-param Action<Controller> $action
*/
public function beforeAction($action)
{
@@ -745,6 +748,9 @@ class Module extends ServiceLocator
* @param Action $action the action just executed.
* @param mixed $result the action return result.
* @return mixed the processed action result.
*
* @phpstan-param Action<Controller> $action
* @psalm-param Action<Controller> $action
*/
public function afterAction($action, $result)
{

View File

@@ -192,8 +192,8 @@ class Controller extends \yii\base\Controller
* @return array the valid parameters that the action can run with.
* @throws Exception if there are unknown options or missing arguments
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params
@@ -546,8 +546,8 @@ class Controller extends \yii\base\Controller
* @param Action $action action to get summary for
* @return string a one-line short summary describing the specified action.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function getActionHelpSummary($action)
{
@@ -563,8 +563,8 @@ class Controller extends \yii\base\Controller
* @param Action $action action to get help for
* @return string the detailed help information for the specified action.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function getActionHelp($action)
{
@@ -588,8 +588,8 @@ class Controller extends \yii\base\Controller
* @param Action $action the action instance
* @return array the help information of the action arguments
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function getActionArgsHelp($action)
{
@@ -664,8 +664,8 @@ class Controller extends \yii\base\Controller
* @param Action $action
* @return array the help information of the action options
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function getActionOptionsHelp($action)
{
@@ -722,8 +722,8 @@ class Controller extends \yii\base\Controller
* @param Action $action
* @return \ReflectionFunctionAbstract
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
protected function getActionMethodReflection($action)
{

View File

@@ -127,8 +127,8 @@ abstract class BaseMigrateController extends Controller
* @throws InvalidConfigException if directory specified in migrationPath doesn't exist and action isn't "create".
* @return bool whether the action should continue to be executed.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function beforeAction($action)
{

View File

@@ -178,8 +178,8 @@ class MigrateController extends BaseMigrateController
* @param Action $action the action to be executed.
* @return bool whether the action should continue to be executed.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*/
public function beforeAction($action)
{

View File

@@ -9,6 +9,7 @@ namespace yii\filters;
use Yii;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\di\Instance;
use yii\web\ForbiddenHttpException;
use yii\web\IdentityInterface;
@@ -53,6 +54,9 @@ use yii\web\User;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class AccessControl extends ActionFilter
{

View File

@@ -9,6 +9,7 @@ namespace yii\filters;
use Yii;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\web\BadRequestHttpException;
use yii\web\Request;
@@ -29,6 +30,9 @@ use yii\web\Request;
*
* @author Dmitry Dorogin <dmirogin@ya.ru>
* @since 2.0.13
*
* @template T of Component
* @extends ActionFilter<T>
*/
class AjaxFilter extends ActionFilter
{

View File

@@ -10,6 +10,7 @@ namespace yii\filters;
use Yii;
use yii\base\ActionFilter;
use yii\base\BootstrapInterface;
use yii\base\Component;
use yii\web\BadRequestHttpException;
use yii\web\NotAcceptableHttpException;
use yii\web\Request;
@@ -82,6 +83,9 @@ use yii\web\Response;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class ContentNegotiator extends ActionFilter implements BootstrapInterface
{

View File

@@ -10,6 +10,7 @@ namespace yii\filters;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\Controller;
use yii\base\InvalidConfigException;
use yii\web\Request;
@@ -68,6 +69,9 @@ use yii\web\Response;
*
* @author Philippe Gaultier <pgaultier@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class Cors extends ActionFilter
{

View File

@@ -10,6 +10,7 @@ namespace yii\filters;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\Controller;
use yii\helpers\StringHelper;
use yii\web\NotFoundHttpException;
@@ -65,6 +66,9 @@ use yii\web\NotFoundHttpException;
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0.11
*
* @template T of Component
* @extends ActionFilter<T>
*/
class HostControl extends ActionFilter
{

View File

@@ -9,6 +9,7 @@ namespace yii\filters;
use Yii;
use yii\base\ActionFilter;
use yii\base\Component;
/**
* HttpCache implements client-side caching by utilizing the `Last-Modified` and `ETag` HTTP headers.
@@ -41,6 +42,9 @@ use yii\base\ActionFilter;
* @author Da:Sourcerer <webmaster@dasourcerer.net>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class HttpCache extends ActionFilter
{

View File

@@ -10,6 +10,7 @@ namespace yii\filters;
use Closure;
use Yii;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\DynamicContentAwareInterface;
use yii\base\DynamicContentAwareTrait;
use yii\caching\CacheInterface;
@@ -50,6 +51,9 @@ use yii\web\Response;
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Sergey Makinen <sergey@makinen.ru>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class PageCache extends ActionFilter implements DynamicContentAwareInterface
{

View File

@@ -11,6 +11,7 @@ use Closure;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\Controller;
use yii\web\IdentityInterface;
use yii\web\Request;
@@ -40,6 +41,9 @@ use yii\web\TooManyRequestsHttpException;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
class RateLimiter extends ActionFilter
{

View File

@@ -8,6 +8,7 @@
namespace yii\filters;
use Yii;
use yii\base\Action;
use yii\base\ActionEvent;
use yii\base\Behavior;
use yii\web\Controller;
@@ -89,6 +90,9 @@ class VerbFilter extends Behavior
* @param ActionEvent $event
* @return bool
* @throws MethodNotAllowedHttpException when the request method is not allowed.
*
* @phpstan-param ActionEvent<Action<Controller>> $event
* @psalm-param ActionEvent<Action<Controller>> $event
*/
public function beforeAction($event)
{

View File

@@ -10,6 +10,7 @@ namespace yii\filters\auth;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\Controller;
use yii\helpers\StringHelper;
use yii\web\IdentityInterface;
@@ -23,6 +24,9 @@ use yii\web\User;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends ActionFilter<T>
*/
abstract class AuthMethod extends ActionFilter implements AuthInterface
{

View File

@@ -9,6 +9,7 @@ namespace yii\filters\auth;
use Yii;
use yii\base\ActionFilter;
use yii\base\Component;
use yii\base\Controller;
use yii\base\InvalidConfigException;
@@ -37,6 +38,9 @@ use yii\base\InvalidConfigException;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends AuthMethod<T>
*/
class CompositeAuth extends AuthMethod
{

View File

@@ -7,6 +7,8 @@
namespace yii\filters\auth;
use yii\base\Component;
/**
* HttpBasicAuth is an action filter that supports the HTTP Basic authentication method.
*
@@ -56,6 +58,9 @@ namespace yii\filters\auth;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends AuthMethod<T>
*/
class HttpBasicAuth extends AuthMethod
{

View File

@@ -7,6 +7,8 @@
namespace yii\filters\auth;
use yii\base\Component;
/**
* HttpBearerAuth is an action filter that supports the authentication method based on HTTP Bearer token.
*
@@ -25,6 +27,9 @@ namespace yii\filters\auth;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends HttpHeaderAuth<T>
*/
class HttpBearerAuth extends HttpHeaderAuth
{

View File

@@ -7,6 +7,8 @@
namespace yii\filters\auth;
use yii\base\Component;
/**
* HttpHeaderAuth is an action filter that supports HTTP authentication through HTTP Headers.
*
@@ -30,6 +32,9 @@ namespace yii\filters\auth;
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Benoît Boure <benoit.boure@gmail.com>
* @since 2.0.14
*
* @template T of Component
* @extends AuthMethod<T>
*/
class HttpHeaderAuth extends AuthMethod
{

View File

@@ -7,11 +7,16 @@
namespace yii\filters\auth;
use yii\base\Component;
/**
* QueryParamAuth is an action filter that supports the authentication based on the access token passed through a query parameter.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of Component
* @extends AuthMethod<T>
*/
class QueryParamAuth extends AuthMethod
{

View File

@@ -121,8 +121,8 @@ class Controller extends \yii\base\Controller
* @return array the valid parameters that the action can run with.
* @throws BadRequestHttpException if there are missing or invalid parameters.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
* @phpstan-param Action<$this> $action
* @psalm-param Action<$this> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params