Passed
Push — master ( 8a373e...617e52 )
by Arthur
22:06
created

GeneratorManager::createAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 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 $modelName
95 2
     */
96
    public function createAttribute(string $attributeName)
97 2
    {
98 2
        $options = [
99
            "name" => $attributeName,
100 1
        ];
101
        $this->call('attribute', $options);
102
    }
103 1
104 1
    /**
105 1
     * @param string $serviceName
106
     */
107 1
    public function createService(string $serviceName)
108 1
    {
109
        $options = [
110
            "name" => $serviceName,
111
        ];
112
        $this->call('service', $options);
113
    }
114
115
    /**
116
     * @param string $serviceName
117
     */
118
    public function createServiceContract(string $serviceContractName)
119
    {
120
        $options = [
121
            "name" => $serviceContractName,
122
        ];
123
        $this->call('service-contract', $options);
124
    }
125
126
    /**
127
     * @param string $policyName
128
     */
129
    public function createPolicy(string $policyName)
130
    {
131
        $options = [
132
            "name" => $policyName,
133
        ];
134
        $this->call('policy', $options);
135
    }
136
137
    /**
138
     * @param string $eventName
139
     */
140
    public function createEvent(string $eventName)
141
    {
142
        $options = [
143
            "name" => $eventName,
144
        ];
145
        $this->call('event', $options);
146
    }
147
148
    /**
149
     * @param string $notificationName
150
     */
151
    public function createNotification(string $notificationName)
152
    {
153
        $options = [
154
            "name" => $notificationName,
155
        ];
156
        $this->call('notification', $options);
157
    }
158
159
    /**
160
     * @param string $providerName
161
     */
162
    public function createServiceProvider(string $providerName)
163
    {
164
        $options = [
165
            "name" => $providerName,
166
        ];
167
        $this->call('provider', $options);
168
    }
169
170
    /**
171
     * @param string $seederName
172
     */
173
    public function createSeeder(string $seederName)
174
    {
175
        $options = [
176
            "name" => $seederName,
177
        ];
178
        $this->call('seeder', $options);
179
    }
180
181
    /**
182
     * @param string $middlewareName
183
     */
184
    public function createMiddleware(string $middlewareName)
185
    {
186
        $options = [
187
            "name" => $middlewareName,
188
        ];
189
        $this->call('middleware', $options);
190
    }
191
192
    /**
193
     * @param string $requestName
194
     */
195
    public function createRequest(string $requestName)
196
    {
197
        $options = [
198
            "name" => $requestName,
199
        ];
200
        $this->call('request', $options);
201
    }
202
203
    /**
204
     * @param string $ruleName
205
     */
206
    public function createRule(string $ruleName)
207
    {
208
        $options = [
209
            "name" => $ruleName,
210
        ];
211
        $this->call('rule', $options);
212
    }
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
    public function createPermission(string $permissionName)
229
    {
230
        $options = [
231
            "name" => $permissionName,
232
        ];
233
        $this->call('permission', $options);
234
    }
235
236
    /**
237
     * @param string $moduleName
238
     */
239
    public function createRoute()
240
    {
241
        $options = [
242
243
        ];
244
        $this->call('route', $options);
245
    }
246
247
    /**
248
     * @param string $moduleName
249
     */
250
    public function createComposer()
251
    {
252
        $this->call('composer', []);
253
    }
254
255
    /**
256
     * @param string $testName
257
     * @param string $type
258
     */
259
    public function createTest(string $testName, string $type)
260
    {
261
        $options = [
262
            "name" => $testName,
263
            "--type" => $type
264
        ];
265
        $this->call('test', $options);
266
    }
267
268
    /**
269
     * @param string $modelName
270
     */
271
    public function createFactory(string $modelName)
272
    {
273
        $options = [
274
            "--model" => $modelName,
275
        ];
276
        $this->call('factory', $options);
277
    }
278
279
    /**
280
     * @param string $transformerName
281
     * @param string $modelName
282
     */
283
    public function createTransformer(string $transformerName, string $modelName)
284
    {
285
        $options = [
286
            "name" => $transformerName,
287
            "--model" => $modelName,
288
        ];
289
        $this->call('transformer', $options);
290
    }
291
292
    /**
293
     * @param string $listenerName
294
     * @param string $eventName
295
     * @param bool $queued
296
     */
297
    public function createListener(string $listenerName, string $eventName, bool $queued = false)
298
    {
299
        $options = [
300
            "name" => $listenerName,
301
            "--event" => $eventName,
302
            "--queued" => $queued
303
        ];
304
        $this->call('listener', $options);
305
    }
306
307
    /**
308
     * @param string $jobName
309
     * @param bool $sync
310
     */
311
    public function createJob(string $jobName, bool $sync = false)
312
    {
313
        $options = [
314
            "name" => $jobName,
315
            "--sync" => $sync
316
        ];
317
        $this->call('job', $options);
318
    }
319
320
    /**
321
     * @param string $jobName
322
     * @param string|null $commandName
323
     */
324
    public function createCommand(string $name, ?string $commandName = null)
325
    {
326
        $options = [
327
            "name" => $name,
328
            "--command" => $commandName
329
        ];
330
        $this->call('command', $options);
331
    }
332
333
    /**
334
     * @param string $modelName
335
     * @param bool $mongo
336
     * @param bool $migration
337
     */
338
    public function createModel(string $modelName, ?bool $mongo = false, ?bool $migration = true)
339
    {
340
        $options = [
341
            "name" => $modelName,
342
            "--mongo" => $mongo,
343
            "--migration" => $migration
344
        ];
345
        $this->call('model', $options);
346
    }
347
348
349
}
350