Conditions | 2 |
Paths | 2 |
Total Lines | 29 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php namespace Comodojo\Extender\Socket\Commands\Worklog; |
||
13 | public static function execute(Parameters $params, Daemon $daemon) { |
||
14 | |||
15 | $filter = $params->get('filter'); |
||
16 | |||
17 | $manager = new Manager( |
||
18 | $daemon->getConfiguration(), |
||
|
|||
19 | $daemon->getLogger(), |
||
20 | $daemon->getEvents() |
||
21 | ); |
||
22 | |||
23 | if ( empty($filter) ) { |
||
24 | $data = $manager->get(); |
||
25 | } else { |
||
26 | $f = Filter::createFromExport($filter); |
||
27 | $data = $manager->get( |
||
28 | [], |
||
29 | $f->getLimit(), |
||
30 | $f->getOffset(), |
||
31 | $f->getReverse() |
||
32 | ); |
||
33 | } |
||
34 | |||
35 | $resource = new Collection($data, new WorklogTransformer); |
||
36 | $fractal = new FractalManager(); |
||
37 | $data = $fractal->createData($resource)->toArray(); |
||
38 | |||
39 | return $data['data']; |
||
40 | |||
41 | } |
||
42 | |||
44 |
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: