Fix #20433: Added PHPStan/Psalm annotations for some controllers methods: beforeAction, afterAction and bindActionParams

This commit is contained in:
Максим Спирков
2025-07-08 13:33:57 +05:00
committed by GitHub
parent 4ab002b59a
commit 52f28ee2ec
4 changed files with 37 additions and 3 deletions

View File

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.54 under development 2.0.54 under development
------------------------ ------------------------
- no changes in this release. - Enh #20433: Added PHPStan/Psalm annotations for some controllers methods: `beforeAction`, `afterAction` and `bindActionParams` (max-s-lab)
2.0.53 June 27, 2025 2.0.53 June 27, 2025

View File

@ -227,6 +227,15 @@ class Controller extends Component implements ViewContextInterface
* @param Action $action the action to be bound with parameters. * @param Action $action the action to be bound with parameters.
* @param array $params the parameters to be bound to the action. * @param array $params the parameters to be bound to the action.
* @return array the valid parameters that the action can run with. * @return array the valid parameters that the action can run with.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params
*
* @phpstan-return mixed[]
* @psalm-return mixed[]
*/ */
public function bindActionParams($action, $params) public function bindActionParams($action, $params)
{ {
@ -296,6 +305,9 @@ class Controller extends Component implements ViewContextInterface
* *
* @param Action $action the action to be executed. * @param Action $action the action to be executed.
* @return bool whether the action should continue to run. * @return bool whether the action should continue to run.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
*/ */
public function beforeAction($action) public function beforeAction($action)
{ {
@ -324,6 +336,9 @@ class Controller extends Component implements ViewContextInterface
* @param Action $action the action just executed. * @param Action $action the action just executed.
* @param mixed $result the action return result. * @param mixed $result the action return result.
* @return mixed the processed action result. * @return mixed the processed action result.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
*/ */
public function afterAction($action, $result) public function afterAction($action, $result)
{ {

View File

@ -189,6 +189,15 @@ class Controller extends \yii\base\Controller
* @param array $params the parameters to be bound to the action * @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with. * @return array the valid parameters that the action can run with.
* @throws Exception if there are unknown options or missing arguments * @throws Exception if there are unknown options or missing arguments
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params
*
* @phpstan-return mixed[]
* @psalm-return mixed[]
*/ */
public function bindActionParams($action, $params) public function bindActionParams($action, $params)
{ {

View File

@ -11,6 +11,7 @@ use Yii;
use yii\base\Exception; use yii\base\Exception;
use yii\base\InlineAction; use yii\base\InlineAction;
use yii\helpers\Url; use yii\helpers\Url;
use yii\base\Action;
/** /**
* Controller is the base class of web controllers. * Controller is the base class of web controllers.
@ -108,14 +109,23 @@ class Controller extends \yii\base\Controller
/** /**
* Binds the parameters to the action. * Binds the parameters to the action.
* This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters. * This method is invoked by [[Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return * This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter, * the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown. * an exception will be thrown.
* @param \yii\base\Action $action the action to be bound with parameters * @param Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action * @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with. * @return array the valid parameters that the action can run with.
* @throws BadRequestHttpException if there are missing or invalid parameters. * @throws BadRequestHttpException if there are missing or invalid parameters.
*
* @phpstan-param Action<static> $action
* @psalm-param Action<static> $action
*
* @phpstan-param array<array-key, mixed> $params
* @psalm-param array<array-key, mixed> $params
*
* @phpstan-return mixed[]
* @psalm-return mixed[]
*/ */
public function bindActionParams($action, $params) public function bindActionParams($action, $params)
{ {