1 | <?php |
||
23 | class AdministrationController extends Controller |
||
24 | { |
||
25 | /** |
||
26 | * Show general application stats |
||
27 | * |
||
28 | * @param Tag $tag |
||
29 | * @param Project $project |
||
30 | * @param User $user |
||
31 | * |
||
32 | * @return \Illuminate\View\View |
||
33 | */ |
||
34 | 1 | public function getIndex(Tag $tag, Project $project, User $user) |
|
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 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: