Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | protected function mapConfig(JobBase $job) : array { |
||
28 | $body = [ |
||
29 | 'auto_delete' => $job->isAutoDelete(), |
||
30 | 'durable' => $job->isDurable(), |
||
31 | 'arguments' => [] // TODO |
||
32 | ]; |
||
33 | |||
34 | foreach($job->getArguments() as $argument) { |
||
35 | $body['arguments'][$argument->getArgumentName()] = $argument->getValue(); |
||
36 | }; |
||
37 | |||
38 | return array_merge(parent::mapConfig($job), [ |
||
39 | 'json' => $body, |
||
40 | ]); |
||
41 | } |
||
42 | } |
||
43 |
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: