Passed
Push — master ( ff4e9f...624a9a )
by Arthur
35:46
created

GeneratorManager   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 328
Duplicated Lines 0 %

Test Coverage

Coverage 96.61%

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 328
ccs 114
cts 118
cp 0.9661
rs 10
c 0
b 0
f 0
wmc 29

28 Methods

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