From 503828ef3a1decfe92e5b96dd5ab6d5eeea57961 Mon Sep 17 00:00:00 2001 From: Maksim Spirkov <63721828+mspirkov@users.noreply.github.com> Date: Tue, 28 Oct 2025 14:58:17 +0300 Subject: [PATCH] Add missing generics in `yii\validators` and `yii\log` namespaces (#20644) --- framework/log/Target.php | 7 ++++++- framework/validators/ExistValidator.php | 10 ++++++++-- framework/validators/UniqueValidator.php | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/framework/log/Target.php b/framework/log/Target.php index 2e0ebda6d7..aa6d614af8 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -13,7 +13,9 @@ use yii\base\InvalidConfigException; use yii\helpers\ArrayHelper; use yii\helpers\StringHelper; use yii\helpers\VarDumper; +use yii\web\IdentityInterface; use yii\web\Request; +use yii\web\User; /** * Target is the base class for all log target classes. @@ -344,7 +346,10 @@ abstract class Target extends Component $request = Yii::$app->getRequest(); $ip = $request instanceof Request ? $request->getUserIP() : '-'; - /** @var \yii\web\User $user */ + /** + * @var User $user + * @phpstan-var User + */ $user = Yii::$app->has('user', true) ? Yii::$app->get('user') : null; if ($user && ($identity = $user->getIdentity(false))) { $userID = $identity->getId(); diff --git a/framework/validators/ExistValidator.php b/framework/validators/ExistValidator.php index 185d59456a..cce93b26ae 100644 --- a/framework/validators/ExistValidator.php +++ b/framework/validators/ExistValidator.php @@ -116,13 +116,17 @@ class ExistValidator extends Validator /** * Validates existence of the current attribute based on relation name - * @param \yii\db\ActiveRecord $model the data model to be validated + * @param ActiveRecord $model the data model to be validated * @param string $attribute the name of the attribute to be validated. */ private function checkTargetRelationExistence($model, $attribute) { $exists = false; - /** @var ActiveQuery $relationQuery */ + + /** + * @var ActiveQuery $relationQuery + * @phpstan-var ActiveQuery + */ $relationQuery = $model->{'get' . ucfirst($this->targetRelation)}(); if ($this->filter instanceof \Closure) { @@ -316,6 +320,8 @@ class ExistValidator extends Validator * @param array $conditions array of condition, keys to be modified * @param string|null $alias set empty string for no apply alias. Set null for apply primary table alias * @return array + * + * @phpstan-param ActiveQuery $query */ private function applyTableAlias($query, $conditions, $alias = null) { diff --git a/framework/validators/UniqueValidator.php b/framework/validators/UniqueValidator.php index acae711c16..34f87ce04b 100644 --- a/framework/validators/UniqueValidator.php +++ b/framework/validators/UniqueValidator.php @@ -241,6 +241,8 @@ class UniqueValidator extends Validator * @param array $conditions conditions, compatible with [[\yii\db\Query::where()|Query::where()]] key-value format * * @return ActiveQueryInterface|ActiveQuery + * + * @phpstan-return ActiveQueryInterface|ActiveQuery */ private function prepareQuery($targetClass, $conditions) { @@ -319,6 +321,8 @@ class UniqueValidator extends Validator * @param array $conditions array of condition, keys to be modified * @param string|null $alias set empty string for no apply alias. Set null for apply primary table alias * @return array + * + * @phpstan-param ActiveQuery $query */ private function applyTableAlias($query, $conditions, $alias = null) {