1 | <?php |
||
15 | class TmdbServiceProvider extends ServiceProvider |
||
16 | { |
||
17 | /** |
||
18 | * Indicates if loading of the provider is deferred. |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $defer = false; |
||
23 | |||
24 | /** |
||
25 | * Actual provider |
||
26 | * |
||
27 | * @var \Illuminate\Support\ServiceProvider |
||
28 | */ |
||
29 | protected $provider; |
||
30 | |||
31 | /** |
||
32 | * Construct the TMDB service provider |
||
33 | */ |
||
34 | public function __construct() |
||
45 | |||
46 | /** |
||
47 | * Bootstrap the application events. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function boot() |
||
55 | |||
56 | /** |
||
57 | * Register the service provider. |
||
58 | * |
||
59 | * @return void |
||
60 | */ |
||
61 | public function register() |
||
91 | |||
92 | /** |
||
93 | * Register the ServiceProvider according to Laravel version |
||
94 | * |
||
95 | * @return \Tmdb\Laravel\Provider\ProviderInterface |
||
96 | */ |
||
97 | private function registerProvider() |
||
106 | |||
107 | /** |
||
108 | * Get the services provided by the provider. |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | public function provides() |
||
116 | } |
||
117 |
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: