Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
21 | public function beforeAction($action) |
||
22 | { |
||
23 | /** @var Module $module */ |
||
24 | $module = Yii::$app->getModule('user'); |
||
25 | $maxPasswordAge = $module->maxPasswordAge; |
||
26 | // If feature is not set do nothing (or raise a configuration error?) |
||
27 | if (is_null($maxPasswordAge)) { |
||
28 | return parent::beforeAction($action); |
||
29 | } |
||
30 | if (Yii::$app->user->isGuest) { |
||
31 | // Not our business |
||
32 | return parent::beforeAction($action); |
||
33 | } |
||
34 | /** @var User $identity */ |
||
35 | $identity = Yii::$app->user->identity; |
||
36 | if ($identity->password_age >= $maxPasswordAge) { |
||
37 | // Force password change |
||
38 | Yii::$app->getSession()->setFlash('warning', Yii::t('usuario', 'Your password has expired, you must change it now')); |
||
|
|||
39 | return Yii::$app->response->redirect(['/user/settings/account'])->send(); |
||
40 | } |
||
41 | |||
42 | return parent::beforeAction($action); |
||
43 | } |
||
44 | } |
||
45 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: