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