| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 28 | 
| Code Lines | 18 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 6 | 
| Changes | 0 | ||
| 1 | <?php namespace Comodojo\Extender\Socket\Commands\Scheduler;  | 
            ||
| 11 |     public static function execute(Parameters $params, Daemon $daemon) { | 
            ||
| 12 | |||
| 13 | $manager = new Manager(  | 
            ||
| 14 | $daemon->getConfiguration(),  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 15 | $daemon->getLogger(),  | 
            ||
| 16 | $daemon->getEvents()  | 
            ||
| 17 | );  | 
            ||
| 18 | |||
| 19 |         $id = $params->get('id'); | 
            ||
| 20 |         $name = $params->get('name'); | 
            ||
| 21 | |||
| 22 | $schedule = empty($id) ? $manager->getByName($name) :  | 
            ||
| 23 | $manager->get($id);  | 
            ||
| 24 | |||
| 25 | $request = $schedule->getRequest();  | 
            ||
| 26 | |||
| 27 | $schedule_message = new ScheduleMessage();  | 
            ||
| 28 | $schedule_message->setId($schedule->getId());  | 
            ||
| 29 | $schedule_message->setName($schedule->getName());  | 
            ||
| 30 | $schedule_message->setDescription($schedule->getDescription());  | 
            ||
| 31 | $schedule_message->setExpression((string)$schedule->getExpression());  | 
            ||
| 32 | $schedule_message->setEnabled($schedule->getEnabled());  | 
            ||
| 33 | |||
| 34 | $request_message = $request->convertToMessage();  | 
            ||
| 35 | |||
| 36 | return [$schedule_message->export(), $request_message->export()];  | 
            ||
| 37 | |||
| 38 | }  | 
            ||
| 39 | |||
| 41 | 
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: