1 | <?php |
||
11 | class Driver |
||
12 | { |
||
13 | use EventsEmitter; |
||
14 | |||
15 | /** |
||
16 | * @var Project |
||
17 | */ |
||
18 | protected $project; |
||
19 | /** |
||
20 | * @var Notification |
||
21 | */ |
||
22 | protected $notification; |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $subscribers; |
||
27 | /** |
||
28 | * @var PayloadStorageContract |
||
29 | */ |
||
30 | protected $payloadStorage; |
||
31 | /** |
||
32 | * @var Statistics |
||
33 | */ |
||
34 | protected $statisticsStorage; |
||
35 | |||
36 | /** |
||
37 | * Create a new Driver. |
||
38 | * |
||
39 | * @param Project $project |
||
40 | * @param PayloadStorageContract $payloadStorage |
||
41 | * @param Statistics $statisticsStorage |
||
42 | */ |
||
43 | 9 | public function __construct(Project $project, PayloadStorageContract $payloadStorage = null, Statistics $statisticsStorage = null) |
|
51 | |||
52 | /** |
||
53 | * Boot driver. |
||
54 | */ |
||
55 | 9 | public function boot() |
|
59 | |||
60 | /** |
||
61 | * Send notification. |
||
62 | * |
||
63 | * @param Notification $notification |
||
64 | * @return $this |
||
65 | */ |
||
66 | 5 | public function send(Notification $notification) |
|
72 | |||
73 | /** |
||
74 | * Endpoints to send to. |
||
75 | * |
||
76 | * @param array $subscribers |
||
77 | * @return $this |
||
78 | */ |
||
79 | 5 | public function to(array $subscribers) |
|
85 | |||
86 | /** |
||
87 | * Send notification. |
||
88 | */ |
||
89 | 5 | public function flush() |
|
103 | |||
104 | /** |
||
105 | * Generate connection package. |
||
106 | * |
||
107 | * @param string $provider |
||
108 | * @param array $extra |
||
109 | */ |
||
110 | 1 | public function sendPackage($provider, $extra = []) |
|
114 | |||
115 | /** |
||
116 | * Cast provider. |
||
117 | * |
||
118 | * @param string $name |
||
119 | * @return AbstractProvider |
||
120 | * @throws \RuntimeException |
||
121 | */ |
||
122 | 4 | public function provider($name) |
|
126 | |||
127 | /** |
||
128 | * Prepare notifications. |
||
129 | * Split subscribers by their providers and prepare payload. |
||
130 | */ |
||
131 | 4 | protected function splitSubscribers() |
|
160 | |||
161 | /** |
||
162 | * Validate data. |
||
163 | * |
||
164 | * @throws \RuntimeException |
||
165 | */ |
||
166 | 5 | protected function validate() |
|
176 | |||
177 | /** |
||
178 | * Set project manually. |
||
179 | * |
||
180 | * @param Project $project |
||
181 | * @return $this |
||
182 | */ |
||
183 | 1 | public function setProject(Project $project) |
|
189 | |||
190 | /** |
||
191 | * Get project instance. |
||
192 | * |
||
193 | * @return Project |
||
194 | */ |
||
195 | 1 | public function getProject() |
|
199 | |||
200 | /** |
||
201 | * Boot event listeners. |
||
202 | */ |
||
203 | 9 | protected function bootListeners() |
|
209 | } |
||
210 |
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: