1 | <?php |
||
26 | class AdministrationController extends Controller |
||
27 | { |
||
28 | /** |
||
29 | * Show general application stats |
||
30 | * |
||
31 | * @param Tag $tag |
||
32 | * @param Project $project |
||
33 | * @param User $user |
||
34 | * |
||
35 | * @return \Illuminate\View\View |
||
36 | */ |
||
37 | 1 | public function getIndex(Tag $tag, Project $project, User $user) |
|
49 | |||
50 | /** |
||
51 | * Add new tag page |
||
52 | * |
||
53 | * @param FormSettings $form |
||
54 | * |
||
55 | * @return \Illuminate\View\View |
||
56 | */ |
||
57 | public function getSettings(FormSettings $form) |
||
64 | |||
65 | /** |
||
66 | * To create new tag |
||
67 | * |
||
68 | * @param Settings $settings |
||
69 | * @param FormRequest\Settings $request |
||
70 | * |
||
71 | * @return \Illuminate\Http\RedirectResponse |
||
72 | */ |
||
73 | public function postSettings(Settings $settings, FormRequest\Settings $request) |
||
89 | |||
90 | } |
||
91 |
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: