Conditions | 3 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php namespace Comodojo\Extender\Socket\Commands\Queue; |
||
13 | public static function execute(Parameters $params, Daemon $daemon) { |
||
14 | |||
15 | $messages = $params->get('requests'); |
||
16 | |||
17 | $requests = []; |
||
18 | |||
19 | try { |
||
20 | foreach ($messages as $message) { |
||
21 | $requests[] = TaskRequest::createFromMessage( |
||
22 | TaskRequestMessage::createFromExport($message) |
||
23 | ); |
||
24 | } |
||
25 | } catch (Exception $e) { |
||
26 | throw new RpcException("Invalid message payload in request", -32600); |
||
27 | } |
||
28 | |||
29 | $manager = new Manager( |
||
30 | $daemon->getConfiguration(), |
||
|
|||
31 | $daemon->getLogger(), |
||
32 | $daemon->getEvents() |
||
33 | ); |
||
34 | |||
35 | return $manager->addBulk($requests); |
||
36 | |||
37 | } |
||
38 | |||
40 |
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: