Completed
Push — master ( e481c7...bcdb1b )
by Marco
35:35 queued 20:00
created

SocketInjector::inject()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 213
Code Lines 164

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 164
nc 1
nop 1
dl 0
loc 213
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php namespace Comodojo\Extender\Socket;
2
3
use \Comodojo\Daemon\Daemon as AbstractDaemon;
4
use \Comodojo\RpcServer\RpcMethod;
5
6
/**
7
* @package     Comodojo Extender
8
* @author      Marco Giovinazzi <[email protected]>
9
* @license     MIT
10
*
11
* LICENSE:
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
* THE SOFTWARE.
20
 */
21
22
class SocketInjector {
23
24
    public static function inject(AbstractDaemon $daemon) {
25
26
        $mmanager = $daemon->getSocket()->getRpcServer()->methods();
27
28
        // ******************
29
        // Scheduler Commands
30
        // ******************
31
32
        $mmanager->add(
33
            RpcMethod::create(
34
                "scheduler.refresh",
35
                 'Comodojo\Extender\Socket\Commands\Scheduler\Refresh::execute',
36
                 $daemon)
37
            ->setDescription("Refresh current scheduler's schedule")
38
            ->setReturnType('boolean')
39
        );
40
41
        $mmanager->add(
42
            RpcMethod::create(
43
                "scheduler.info",
44
                 'Comodojo\Extender\Socket\Commands\Scheduler\Info::execute',
45
                 $daemon)
46
            ->setDescription("Refresh current scheduler status")
47
            ->setReturnType('array')
48
        );
49
50
        $mmanager->add(
51
            RpcMethod::create(
52
                "scheduler.add",
53
                 'Comodojo\Extender\Socket\Commands\Scheduler\Add::execute',
54
                 $daemon)
55
            ->setDescription("Set new schedule")
56
            ->addParameter('struct', 'schedule')
57
            ->addParameter('struct', 'request')
58
            ->setReturnType('int')
59
        );
60
61
        $mmanager->add(
62
            RpcMethod::create(
63
                "scheduler.list",
64
                 'Comodojo\Extender\Socket\Commands\Scheduler\GetList::execute',
65
                 $daemon)
66
            ->setDescription("List all installed schedules")
67
            ->setReturnType('array')
68
        );
69
70
        $mmanager->add(
71
            RpcMethod::create(
72
                "scheduler.get",
73
                 'Comodojo\Extender\Socket\Commands\Scheduler\Get::execute',
74
                 $daemon)
75
            ->setDescription("Get a schedule and related task request by id (int) or name (string)")
76
            ->addParameter('int', 'id')
77
            ->setReturnType('array')
78
            ->addSignature()
79
            ->addParameter('string', 'name')
80
            ->setReturnType('array')
81
        );
82
83
        $mmanager->add(
84
            RpcMethod::create(
85
                "scheduler.edit",
86
                 'Comodojo\Extender\Socket\Commands\Scheduler\Edit::execute',
87
                 $daemon)
88
            ->setDescription("Edit a schedule")
89
            ->addParameter('struct', 'schedule')
90
            ->addParameter('struct', 'request')
91
            ->setReturnType('boolean')
92
        );
93
94
        $mmanager->add(
95
            RpcMethod::create(
96
                "scheduler.disable",
97
                 'Comodojo\Extender\Socket\Commands\Scheduler\Disable::execute',
98
                 $daemon)
99
            ->setDescription("Disable a schedule by id (int) or name (string)")
100
            ->addParameter('int', 'id')
101
            ->setReturnType('boolean')
102
            ->addSignature()
103
            ->addParameter('string', 'name')
104
            ->setReturnType('boolean')
105
        );
106
107
        $mmanager->add(
108
            RpcMethod::create(
109
                "scheduler.enable",
110
                 'Comodojo\Extender\Socket\Commands\Scheduler\Enable::execute',
111
                 $daemon)
112
            ->setDescription("Enable a schedule by id (int) or name (string)")
113
            ->addParameter('int', 'id')
114
            ->setReturnType('boolean')
115
            ->addSignature()
116
            ->addParameter('string', 'name')
117
            ->setReturnType('boolean')
118
        );
119
120
        $mmanager->add(
121
            RpcMethod::create(
122
                "scheduler.remove",
123
                 'Comodojo\Extender\Socket\Commands\Scheduler\Remove::execute',
124
                 $daemon)
125
            ->setDescription("Remove a schedule by id (int) or name (string)")
126
            ->addParameter('int', 'id')
127
            ->setReturnType('boolean')
128
            ->addSignature()
129
            ->addParameter('string', 'name')
130
            ->setReturnType('boolean')
131
        );
132
133
        // **************
134
        // Queue Commands
135
        // **************
136
137
        $mmanager->add(
138
            RpcMethod::create(
139
                "queue.info",
140
                 'Comodojo\Extender\Socket\Commands\Queue\Info::execute',
141
                 $daemon)
142
            ->setDescription("Get current queue status")
143
            ->setReturnType('array')
144
        );
145
146
        $mmanager->add(
147
            RpcMethod::create(
148
                "queue.add",
149
                 'Comodojo\Extender\Socket\Commands\Queue\Add::execute',
150
                 $daemon)
151
            ->setDescription("Push new request to queue")
152
            ->addParameter('struct', 'request')
153
            ->setReturnType('string')
154
        );
155
156
        $mmanager->add(
157
            RpcMethod::create(
158
                "queue.addBulk",
159
                 'Comodojo\Extender\Socket\Commands\Queue\AddBulk::execute',
160
                 $daemon)
161
            ->setDescription("Push new requests to queue")
162
            ->addParameter('array', 'requests')
163
            ->setReturnType('array')
164
        );
165
166
        // ****************
167
        // Worklog Commands
168
        // ****************
169
170
        $mmanager->add(
171
            RpcMethod::create(
172
                "worklog.count",
173
                 'Comodojo\Extender\Socket\Commands\Worklog\Count::execute',
174
                 $daemon)
175
            ->setDescription("Count recorded worklogs")
176
            ->setReturnType('int')
177
        );
178
179
        $mmanager->add(
180
            RpcMethod::create(
181
                "worklog.list",
182
                 'Comodojo\Extender\Socket\Commands\Worklog\GetList::execute',
183
                 $daemon)
184
            ->setDescription("Get a list of worklog according to (optional) filter")
185
            ->setReturnType('array')
186
            ->addSignature()
187
            ->addParameter('struct', 'filter')
188
            ->setReturnType('array')
189
        );
190
191
        $mmanager->add(
192
            RpcMethod::create(
193
                "worklog.byId",
194
                 'Comodojo\Extender\Socket\Commands\Worklog\ById::execute',
195
                 $daemon)
196
            ->setDescription("Get a worklog from id")
197
            ->addParameter('int', 'id')
198
            ->setReturnType('struct')
199
        );
200
201
        $mmanager->add(
202
            RpcMethod::create(
203
                "worklog.byUid",
204
                 'Comodojo\Extender\Socket\Commands\Worklog\ByUid::execute',
205
                 $daemon)
206
            ->setDescription("Get a worklog from uid")
207
            ->addParameter('string', 'uid')
208
            ->setReturnType('struct')
209
        );
210
211
        $mmanager->add(
212
            RpcMethod::create(
213
                "worklog.byJid",
214
                 'Comodojo\Extender\Socket\Commands\Worklog\ByJid::execute',
215
                 $daemon)
216
            ->setDescription("Get a list of worklog from job id according to (optional) filter")
217
            ->addParameter('int', 'jid')
218
            ->setReturnType('array')
219
            ->addSignature()
220
            ->addParameter('int', 'jid')
221
            ->addParameter('struct', 'filter')
222
            ->setReturnType('array')
223
        );
224
225
        $mmanager->add(
226
            RpcMethod::create(
227
                "worklog.byPid",
228
                 'Comodojo\Extender\Socket\Commands\Worklog\ByPid::execute',
229
                 $daemon)
230
            ->setDescription("Get a list of worklog from system pid according to (optional) filter")
231
            ->addParameter('int', 'pid')
232
            ->setReturnType('array')
233
            ->addSignature()
234
            ->addParameter('int', 'pid')
235
            ->addParameter('struct', 'filter')
236
            ->setReturnType('array')
237
        );
238
239
    }
240
241
}
242