1 | <?php |
||
22 | class CheckForMaintenanceMode |
||
23 | { |
||
24 | /** |
||
25 | * The Guard implementation. |
||
26 | * |
||
27 | * @var Guard |
||
28 | */ |
||
29 | protected $auth; |
||
30 | |||
31 | /** |
||
32 | * The application implementation. |
||
33 | * |
||
34 | * @var \Illuminate\Contracts\Foundation\Application |
||
35 | */ |
||
36 | protected $app; |
||
37 | |||
38 | /** |
||
39 | * Create a new filter instance. |
||
40 | * |
||
41 | * @param Guard $auth |
||
42 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
43 | */ |
||
44 | 61 | public function __construct(Guard $auth, Application $app) |
|
49 | |||
50 | /** |
||
51 | * Handle an incoming request. |
||
52 | * |
||
53 | * @param \Illuminate\Http\Request $request |
||
54 | * @param \Closure $next |
||
55 | * |
||
56 | * @return mixed |
||
57 | * |
||
58 | * @throws \Symfony\Component\HttpKernel\Exception\HttpException |
||
59 | */ |
||
60 | 61 | public function handle($request, Closure $next) |
|
77 | } |
||
78 |
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: