Conditions | 1 |
Paths | 1 |
Total Lines | 26 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function items() |
||
21 | { |
||
22 | return [ |
||
23 | 'header' => [ |
||
24 | 'label' => $this->render('userMenuHeader'), |
||
25 | ], |
||
26 | 'profile' => [ |
||
27 | 'label' => Yii::t('hipanel', 'Profile'), |
||
28 | 'url' => ['/site/profile'], |
||
29 | ], |
||
30 | 'logout' => [ |
||
31 | 'label' => Yii::t('hipanel', 'Sign out'), |
||
32 | 'url' => ['/site/logout'], |
||
33 | ], |
||
34 | |||
35 | 'deposit' => [ |
||
36 | 'label' => Yii::t('hipanel', 'Recharge account'), |
||
37 | 'url' => ['@pay/deposit'], |
||
38 | 'visible' => Yii::$app->user->can('deposit'), |
||
39 | ], |
||
40 | 'ticket' => [ |
||
41 | 'label' => Yii::t('hipanel', 'Create ticket'), |
||
42 | 'url' => ['@ticket/create'], |
||
43 | ], |
||
44 | ]; |
||
45 | } |
||
46 | } |
||
47 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: