| Conditions | 8 |
| Paths | 12 |
| Total Lines | 56 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace Comodojo\Extender\Socket\Commands\Scheduler; |
||
| 17 | public static function execute(Parameters $params, Daemon $daemon) { |
||
| 18 | |||
| 19 | $schedule_message = $params->get('schedule'); |
||
| 20 | $request_message = $params->get('request'); |
||
| 21 | |||
| 22 | if ( |
||
| 23 | empty($schedule_message['id']) || |
||
| 24 | empty($schedule_message['name']) || |
||
| 25 | empty($schedule_message['expression']) |
||
| 26 | ) { |
||
| 27 | throw new RpcException("Missing schedule name, id or invalid expression", -32600); |
||
| 28 | } |
||
| 29 | |||
| 30 | try { |
||
| 31 | |||
| 32 | $request = TaskRequest::createFromMessage( |
||
| 33 | TaskRequestMessage::createFromExport($request_message) |
||
| 34 | ); |
||
| 35 | |||
| 36 | } catch (Exception $e) { |
||
| 37 | throw new RpcException("Invalid message payload in request", -32600); |
||
| 38 | } |
||
| 39 | |||
| 40 | try { |
||
| 41 | |||
| 42 | $schedule = new Schedule(); |
||
| 43 | $schedule->setId($schedule_message['id']); |
||
| 44 | $schedule->setName($schedule_message['name']); |
||
| 45 | $schedule->setExpression(CronExpression::factory($schedule_message['expression'])); |
||
| 46 | $schedule->setDescription($schedule_message['description']); |
||
| 47 | $schedule->setEnabled($schedule_message['enabled']); |
||
| 48 | $schedule->setRequest($request); |
||
| 49 | |||
| 50 | } catch (Exception $e) { |
||
| 51 | throw new RpcException("Invalid message payload in schedule", -32600); |
||
| 52 | } |
||
| 53 | |||
| 54 | $manager = new Manager( |
||
| 55 | $daemon->getConfiguration(), |
||
|
|
|||
| 56 | $daemon->getLogger(), |
||
| 57 | $daemon->getEvents() |
||
| 58 | ); |
||
| 59 | |||
| 60 | try { |
||
| 61 | $result = $manager->edit($schedule); |
||
| 62 | } catch (InvalidArgumentException $iae) { |
||
| 63 | throw new RpcException("No record could be found", -31002); |
||
| 64 | } catch (Exception $e) { |
||
| 65 | throw new RpcException($e->getMessage(), -32500); |
||
| 66 | } |
||
| 67 | |||
| 68 | $refresh = Refresh::execute($params, $daemon); |
||
| 69 | |||
| 70 | // should method ignore invalid refresh message here? |
||
| 71 | |||
| 72 | return $result; |
||
| 73 | |||
| 77 |