Conditions | 1 |
Paths | 1 |
Total Lines | 14 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
38 | protected function mapConfig(JobBase $job) : array { |
||
39 | $body = [ |
||
40 | 'arguments' => [], |
||
41 | 'destination' => (string)$job->getQueueName(), |
||
42 | 'destination_type' => $job->getDestinationType(), |
||
43 | 'routing_key' => (string)$job->getRoutingKey(), |
||
44 | 'source' => (string)$job->getExchangeName(), |
||
45 | 'vhost' => $job->getVirtualHost(), |
||
46 | ]; |
||
47 | |||
48 | return array_merge(parent::mapConfig($job), [ |
||
49 | 'json' => $body, |
||
50 | ]); |
||
51 | } |
||
52 | } |
||
53 |
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: