Conditions | 7 |
Paths | 11 |
Total Lines | 54 |
Code Lines | 32 |
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; |
||
16 | public static function execute(Parameters $params, Daemon $daemon) { |
||
17 | |||
18 | $schedule_message = $params->get('schedule'); |
||
19 | $request_message = $params->get('request'); |
||
20 | |||
21 | if ( |
||
22 | empty($schedule_message['id']) || |
||
23 | empty($schedule_message['name']) || |
||
24 | empty($schedule_message['expression']) |
||
25 | ) { |
||
26 | throw new RpcException("Missing schedule name, id or invalid expression", -32600); |
||
27 | } |
||
28 | |||
29 | try { |
||
30 | |||
31 | $request = TaskRequest::createFromMessage( |
||
32 | TaskRequestMessage::createFromExport($request_message) |
||
33 | ); |
||
34 | |||
35 | } catch (Exception $e) { |
||
36 | throw new RpcException("Invalid message payload in request", -32600); |
||
37 | } |
||
38 | |||
39 | try { |
||
40 | |||
41 | $schedule = new Schedule(); |
||
42 | $schedule->setId($schedule_message['id']); |
||
43 | $schedule->setName($schedule_message['name']); |
||
44 | $schedule->setExpression(CronExpression::factory($schedule_message['expression'])); |
||
45 | $schedule->setDescription($schedule_message['description']); |
||
46 | $schedule->setEnabled($schedule_message['enabled']); |
||
47 | $schedule->setRequest($request); |
||
48 | |||
49 | } catch (Exception $e) { |
||
50 | throw new RpcException("Invalid message payload in schedule", -32600); |
||
51 | } |
||
52 | |||
53 | $manager = new Manager( |
||
54 | $daemon->getConfiguration(), |
||
|
|||
55 | $daemon->getLogger(), |
||
56 | $daemon->getEvents() |
||
57 | ); |
||
58 | |||
59 | try { |
||
60 | $result = $manager->edit($schedule); |
||
61 | } catch (Exception $e) { |
||
62 | throw new RpcException($e->getMessage(), -32500); |
||
63 | } |
||
64 | |||
65 | $refresh = Refresh::execute($params, $daemon); |
||
66 | |||
67 | // should method ignore invalid refresh message here? |
||
68 | |||
69 | return $result; |
||
70 | |||
74 |