Passed
Push — master ( 40ce26...965fb6 )
by Arthur
22:04
created

GeneratorManager   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 317
Duplicated Lines 0 %

Test Coverage

Coverage 90.74%

Importance

Changes 0
Metric Value
eloc 87
dl 0
loc 317
rs 10
c 0
b 0
f 0
ccs 49
cts 54
cp 0.9074
wmc 28

27 Methods

Rating   Name   Duplication   Size   Complexity  
A module() 0 3 1
A __construct() 0 4 1
A createController() 0 6 1
A call() 0 3 1
A createMigration() 0 8 1
A alterOptions() 0 6 2
A createFactory() 0 6 1
A createModel() 0 8 1
A createRoute() 0 6 1
A createException() 0 6 1
A createComposer() 0 3 1
A createNotification() 0 6 1
A createService() 0 6 1
A createTest() 0 7 1
A createSeeder() 0 6 1
A createServiceProvider() 0 6 1
A createEvent() 0 6 1
A createPermission() 0 6 1
A createCommand() 0 7 1
A createPolicy() 0 6 1
A createRequest() 0 6 1
A createListener() 0 8 1
A createRule() 0 6 1
A createMiddleware() 0 6 1
A createServiceContract() 0 6 1
A createJob() 0 7 1
A createTransformer() 0 7 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 10.03.19
6
 * Time: 18:30
7
 */
8
9
namespace Foundation\Generator\Managers;
10
11
12
use Illuminate\Support\Str;
13
14 2
/**
15
 * Class GeneratorManager
16
 * @package Foundation\Generator\Managers
17 2
 */
18 2
class GeneratorManager
19 2
{
20 2
21
    /**
22 2
     * @var string
23 2
     */
24
    protected $moduleName;
25 1
26
    /**
27
     * @var bool
28 1
     */
29 1
    protected $overwrite;
30
31 1
    /**
32 1
     * GeneratorManager constructor.
33
     * @param string $module
34
     */
35
    protected function __construct(string $module, bool $overwrite = false)
36
    {
37
        $this->moduleName = $module;
38
        $this->overwrite = $overwrite;
39
    }
40
41
    /**
42
     * @param string $moduleName
43 1
     * @return GeneratorManager
44
     */
45
    public static function module(string $moduleName, bool $overwrite = false)
46 1
    {
47 1
        return new GeneratorManager($moduleName, $overwrite);
48
    }
49 1
50 1
    protected function call(string $commandName, $options)
51
    {
52 1
        \Artisan::call("larapi:make:$commandName", $this->alterOptions($options));
53
    }
54
55 1
    /**
56 1
     * @param $options
57
     * @return mixed
58 1
     */
59 1
    protected function alterOptions($options)
60
    {
61 1
        $options['module'] = Str::studly($this->moduleName);
62
        if ($this->overwrite)
63
            $options['--overwrite'] = null;
64 1
        return $options;
65 1
    }
66
67 1
    /**
68 1
     * @param string $migrationName
69
     * @param string $tableName
70 1
     * @param bool $mongo
71
     */
72
    public function createMigration(string $migrationName, string $tableName, bool $mongo = false)
73 1
    {
74 1
        $options = [
75
            "name" => $migrationName,
76 1
            "--table" => $tableName,
77 1
            "--mongo" => $mongo
78
        ];
79 2
        $this->call('migration', $options);
80
    }
81
82 2
    /**
83 2
     * @param string $controllerName
84 2
     */
85 2
    public function createController(string $controllerName)
86
    {
87 2
        $options = [
88 2
            "name" => $controllerName,
89
        ];
90 2
        $this->call('controller', $options);
91
    }
92
93 2
    /**
94 2
     * @param string $serviceName
95 2
     */
96
    public function createService(string $serviceName)
97 2
    {
98 2
        $options = [
99
            "name" => $serviceName,
100 1
        ];
101
        $this->call('service', $options);
102
    }
103 1
104 1
    /**
105 1
     * @param string $serviceName
106
     */
107 1
    public function createServiceContract(string $serviceContractName)
108 1
    {
109
        $options = [
110
            "name" => $serviceContractName,
111
        ];
112
        $this->call('service-contract', $options);
113
    }
114
115
    /**
116
     * @param string $policyName
117
     */
118
    public function createPolicy(string $policyName)
119
    {
120
        $options = [
121
            "name" => $policyName,
122
        ];
123
        $this->call('policy', $options);
124
    }
125
126
    /**
127
     * @param string $eventName
128
     */
129
    public function createEvent(string $eventName)
130
    {
131
        $options = [
132
            "name" => $eventName,
133
        ];
134
        $this->call('event', $options);
135
    }
136
137
    /**
138
     * @param string $notificationName
139
     */
140
    public function createNotification(string $notificationName)
141
    {
142
        $options = [
143
            "name" => $notificationName,
144
        ];
145
        $this->call('notification', $options);
146
    }
147
148
    /**
149
     * @param string $providerName
150
     */
151
    public function createServiceProvider(string $providerName)
152
    {
153
        $options = [
154
            "name" => $providerName,
155
        ];
156
        $this->call('provider', $options);
157
    }
158
159
    /**
160
     * @param string $seederName
161
     */
162
    public function createSeeder(string $seederName)
163
    {
164
        $options = [
165
            "name" => $seederName,
166
        ];
167
        $this->call('seeder', $options);
168
    }
169
170
    /**
171
     * @param string $middlewareName
172
     */
173
    public function createMiddleware(string $middlewareName)
174
    {
175
        $options = [
176
            "name" => $middlewareName,
177
        ];
178
        $this->call('middleware', $options);
179
    }
180
181
    /**
182
     * @param string $requestName
183
     */
184
    public function createRequest(string $requestName)
185
    {
186
        $options = [
187
            "name" => $requestName,
188
        ];
189
        $this->call('request', $options);
190
    }
191
192
    /**
193
     * @param string $ruleName
194
     */
195
    public function createRule(string $ruleName)
196
    {
197
        $options = [
198
            "name" => $ruleName,
199
        ];
200
        $this->call('rule', $options);
201
    }
202
203
    /**
204
     * @param string $exceptionName
205
     */
206
    public function createException(string $exceptionName)
207
    {
208
        $options = [
209
            "name" => $exceptionName,
210
        ];
211
        $this->call('exception', $options);
212
    }
213
214
    /**
215
     * @param string $permissionName
216
     */
217
    public function createPermission(string $permissionName)
218
    {
219
        $options = [
220
            "name" => $permissionName,
221
        ];
222
        $this->call('permission', $options);
223
    }
224
225
    /**
226
     * @param string $moduleName
227
     */
228
    public function createRoute()
229
    {
230
        $options = [
231
232
        ];
233
        $this->call('route', $options);
234
    }
235
236
    /**
237
     * @param string $moduleName
238
     */
239
    public function createComposer()
240
    {
241
        $this->call('composer', []);
242
    }
243
244
    /**
245
     * @param string $testName
246
     * @param string $type
247
     */
248
    public function createTest(string $testName, string $type)
249
    {
250
        $options = [
251
            "name" => $testName,
252
            "--type" => $type
253
        ];
254
        $this->call('test', $options);
255
    }
256
257
    /**
258
     * @param string $modelName
259
     */
260
    public function createFactory(string $modelName)
261
    {
262
        $options = [
263
            "--model" => $modelName,
264
        ];
265
        $this->call('factory', $options);
266
    }
267
268
    /**
269
     * @param string $transformerName
270
     * @param string $modelName
271
     */
272
    public function createTransformer(string $transformerName, string $modelName)
273
    {
274
        $options = [
275
            "name" => $transformerName,
276
            "--model" => $modelName,
277
        ];
278
        $this->call('transformer', $options);
279
    }
280
281
    /**
282
     * @param string $listenerName
283
     * @param string $eventName
284
     * @param bool $queued
285
     */
286
    public function createListener(string $listenerName, string $eventName, bool $queued = false)
287
    {
288
        $options = [
289
            "name" => $listenerName,
290
            "--event" => $eventName,
291
            "--queued" => $queued
292
        ];
293
        $this->call('listener', $options);
294
    }
295
296
    /**
297
     * @param string $jobName
298
     * @param bool $sync
299
     */
300
    public function createJob(string $jobName, bool $sync = false)
301
    {
302
        $options = [
303
            "name" => $jobName,
304
            "--sync" => $sync
305
        ];
306
        $this->call('job', $options);
307
    }
308
309
    /**
310
     * @param string $jobName
311
     * @param string|null $commandName
312
     */
313
    public function createCommand(string $name, ?string $commandName = null)
314
    {
315
        $options = [
316
            "name" => $name,
317
            "--command" => $commandName
318
        ];
319
        $this->call('command', $options);
320
    }
321
322
    /**
323
     * @param string $modelName
324
     * @param bool $mongo
325
     * @param bool $migration
326
     */
327
    public function createModel(string $modelName, ?bool $mongo = false, ?bool $migration = true)
328
    {
329
        $options = [
330
            "name" => $modelName,
331
            "--mongo" => $mongo,
332
            "--migration" => $migration
333
        ];
334
        $this->call('model', $options);
335
    }
336
337
338
}
339