itstructure /
yii2-template-simple
| 1 | <?php |
||
| 2 | |||
| 3 | namespace app\controllers\admin; |
||
| 4 | |||
| 5 | use Yii; |
||
| 6 | use yii\base\InvalidConfigException; |
||
| 7 | use app\components\UserValidateComponent; |
||
| 8 | use app\interfaces\UserValidateComponentInterface; |
||
| 9 | use app\traits\AccessTrait; |
||
| 10 | use app\models\Position; |
||
| 11 | use Itstructure\AdminModule\controllers\CommonAdminController; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Class BaseUserController |
||
| 15 | * BaseUserController implements the CRUD actions for identityClass. |
||
| 16 | * |
||
| 17 | * @property UserValidateComponentInterface|UserValidateComponent $validateComponent Validate component. |
||
| 18 | * |
||
| 19 | * @package app\controllers\admin |
||
| 20 | */ |
||
| 21 | class BaseUserController extends CommonAdminController |
||
| 22 | { |
||
| 23 | use AccessTrait; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | |||
| 25 | /** |
||
| 26 | * Initialize. |
||
| 27 | * Set validateComponent and additionFields. |
||
| 28 | */ |
||
| 29 | public function init() |
||
| 30 | { |
||
| 31 | $this->validateComponent = Yii::$app->get('user-validate'); |
||
|
0 ignored issues
–
show
It seems like
Yii::app->get('user-validate') can also be of type mixed. However, the property $validateComponent is declared as type app\components\UserValid...idateComponentInterface. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 32 | $this->validateComponent->changeRoles = $this->checkAccessToSetRoles(); |
||
| 33 | |||
| 34 | parent::init(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Returns addition fields. |
||
| 39 | * |
||
| 40 | * @throws InvalidConfigException |
||
| 41 | * |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | protected function getAdditionFields(): array |
||
| 45 | { |
||
| 46 | $additionFields = []; |
||
| 47 | |||
| 48 | if ($this->action->id == 'create' || $this->action->id == 'update') { |
||
| 49 | $additionFields['roles'] = $this->validateComponent->getAuthManager()->getRoles(); |
||
| 50 | $additionFields['positions'] = Position::getPositions(); |
||
| 51 | } |
||
| 52 | |||
| 53 | return $additionFields; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Returns identityClass model name. |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | protected function getModelName():string |
||
| 62 | { |
||
| 63 | return \Yii::$app->user->identityClass; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns identityClass Search model name. |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | protected function getSearchModelName():string |
||
| 72 | { |
||
| 73 | return \Yii::$app->user->identityClass . 'Search'; |
||
| 74 | } |
||
| 75 | } |
||
| 76 |