| 1 | <?php |
||
| 20 | class Assignment extends Model |
||
| 21 | { |
||
| 22 | use AuthManagerAwareTrait; |
||
| 23 | |||
| 24 | public $items = []; |
||
| 25 | public $user_id; |
||
| 26 | public $updated = false; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | * |
||
| 31 | * @throws InvalidConfigException |
||
| 32 | */ |
||
| 33 | public function init() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | public function attributeLabels() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | public function rules() |
||
| 65 | } |
||
| 66 |
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 implementation 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 interface: