$attribute; if (empty($value)) { $this->addError($model, $attribute, $this->keyRequired); return; } $activation = $this->findEmailActivationModel($value, $this->type); if ($activation === null) { $this->addError($model, $attribute, $this->notExist); return; } if ($activation->isExpired()) { $this->addError($model, $attribute, $this->expired); return; } $model->$attribute = $activation; } protected function findEmailActivationModel(string $key, int $type = null): ?EmailActivation { $query = EmailActivation::find(); $query->andWhere(['key' => $key]); if ($type !== null) { $query->withType($type); } return $query->one(); } }