Passed
Push — master ( 26c354...92479f )
by Richard
05:49 queued 10s
created

GeneratorConfig   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 296
Duplicated Lines 0 %

Importance

Changes 12
Bugs 1 Features 0
Metric Value
wmc 21
eloc 124
c 12
b 1
f 0
dl 0
loc 296
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
F prepareOptions() 0 41 12
A loadPaths() 0 30 3
A loadDynamicGraphQLVariables() 0 16 1
A loadDynamicVariables() 0 24 3
A prepareGraphQLNames() 0 17 2
1
<?php
2
3
namespace PWWEB\Artomator\Common;
4
5
use Illuminate\Support\Str;
6
use InfyOm\Generator\Common\CommandData as Data;
7
use InfyOm\Generator\Common\GeneratorConfig as Config;
8
9
class GeneratorConfig extends Config
10
{
11
    /**
12
     * Path GraphQL.
13
     *
14
     * @var string
15
     */
16
    public $pathGraphQL;
17
    /**
18
     * Path Contract.
19
     *
20
     * @var string
21
     */
22
    public $pathContract;
23
24
    /**
25
     * GraphQL Name.
26
     *
27
     * @var string
28
     */
29
    public $gName;
30
    /**
31
     * GraphQL Plural.
32
     *
33
     * @var string
34
     */
35
    public $gPlural;
36
    /**
37
     * GraphQL Camel.
38
     *
39
     * @var string
40
     */
41
    public $gCamel;
42
    /**
43
     * GraphQL Camel Plural.
44
     *
45
     * @var string
46
     */
47
    public $gCamelPlural;
48
    /**
49
     * GraphQL Snake.
50
     *
51
     * @var string
52
     */
53
    public $gSnake;
54
    /**
55
     * GraphQL Snake Plural.
56
     *
57
     * @var string
58
     */
59
    public $gSnakePlural;
60
    /**
61
     * GraphQL Dashed.
62
     *
63
     * @var string
64
     */
65
    public $gDashed;
66
    /**
67
     * GraphQL Dashed Plural.
68
     *
69
     * @var string
70
     */
71
    public $gDashedPlural;
72
    /**
73
     * GraphQL Slash.
74
     *
75
     * @var string
76
     */
77
    public $gSlash;
78
    /**
79
     * GraphQL Slash Plural.
80
     *
81
     * @var string
82
     */
83
    public $gSlashPlural;
84
    /**
85
     * GraphQL Human.
86
     *
87
     * @var string
88
     */
89
    public $gHuman;
90
    /**
91
     * GraphQL Human Plural.
92
     *
93
     * @var string
94
     */
95
    public $gHumanPlural;
96
97
    /**
98
     * GraphQL Namespace Contract.
99
     *
100
     * @var string
101
     */
102
    public $nsContract;
103
104
    /**
105
     * Command Options.
106
     *
107
     * @var array
108
     */
109
    public static $availableOptions = [
110
        'fieldsFile',
111
        'jsonFromGUI',
112
        'tableName',
113
        'fromTable',
114
        'ignoreFields',
115
        'save',
116
        'primary',
117
        'prefix',
118
        'paginate',
119
        'skip',
120
        'datatables',
121
        'views',
122
        'relations',
123
        'plural',
124
        'softDelete',
125
        'forceMigrate',
126
        'factory',
127
        'seeder',
128
        'repositoryPattern',
129
        'resources',
130
        'localized',
131
        'connection',
132
        'jqueryDT',
133
        'vue',
134
    ];
135
136
    /**
137
     * Load Paths.
138
     *
139
     * @return void
140
     */
141
    public function loadPaths()
142
    {
143
        parent::loadPaths();
144
145
        $prefix = $this->prefixes['path'];
146
147
        if (false === empty($prefix)) {
148
            $prefix .= '/';
149
        }
150
151
        $viewPrefix = $this->prefixes['view'];
152
153
        if (false === empty($viewPrefix)) {
154
            $viewPrefix .= '/';
155
        }
156
157
        $this->pathFactory = $this->pathFactory.$prefix;
158
159
        $this->pathGraphQL = config('lighthouse.schema.register', base_path('graphql/schema.graphql'));
160
161
        $this->pathVues = config('pwweb.artomator.path.vues', resource_path('js/Pages/')).$viewPrefix.$this->mSnakePlural.'/';
0 ignored issues
show
Bug Best Practice introduced by
The property pathVues does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
162
163
        $this->pathLocales = config('infyom.laravel_generator.path.models_locale_files', base_path('resources/lang/en/models/')).$prefix;
0 ignored issues
show
Bug Best Practice introduced by
The property pathLocales does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
164
165
        $this->pathSchemas = config('infyom.laravel_generator.path.schema_files', resource_path('model_schemas/')).$prefix;
0 ignored issues
show
Bug Best Practice introduced by
The property pathSchemas does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
166
167
        $this->pathContract = config(
168
            'pwweb.artomator.path.contract',
169
            app_path('Contracts/')
170
        ).$prefix;
171
    }
172
173
    /**
174
     * Load Dynamic Variables.
175
     *
176
     * @param Data $commandData Command Data.\
177
     *
178
     * @return Data
179
     */
180
    public function loadDynamicVariables(Data &$commandData)
181
    {
182
        parent::loadDynamicVariables($commandData);
183
        $commandData->addDynamicVariable('$LICENSE_PACKAGE$', config('pwweb.artomator.license.package'));
184
        $commandData->addDynamicVariable('$LICENSE_AUTHORS$', license_authors(config('pwweb.artomator.license.authors')));
185
        $commandData->addDynamicVariable('$LICENSE_COPYRIGHT$', config('pwweb.artomator.license.copyright'));
186
        $commandData->addDynamicVariable('$LICENSE$', config('pwweb.artomator.license.license'));
187
        $commandData->addDynamicVariable('$NAMESPACE_GRAPHQL_MODEL$', str_replace('\\', '\\\\', $this->nsModel));
188
189
        $prefix = $this->prefixes['ns'];
190
191
        if (false === empty($prefix)) {
192
            $prefix = '\\'.$prefix;
193
        }
194
        $this->nsContract = config('pwweb.artomator.namespace.contract', 'App\Contracts').$prefix;
195
        $commandData->addDynamicVariable('$NAMESPACE_CONTRACT$', $this->nsContract);
196
197
        if (false === empty($this->prefixes['view'])) {
198
            $commandData->addDynamicVariable('$VUE_PREFIX$', $this->prefixes['view'].'/');
199
        } else {
200
            $commandData->addDynamicVariable('$VUE_PREFIX$', '');
201
        }
202
203
        return $commandData;
204
    }
205
206
    /**
207
     * Prepare GraphQL Names.
208
     *
209
     * @param string|null $name Name.
210
     *
211
     * @return void
212
     */
213
    public function prepareGraphQLNames($name = null)
214
    {
215
        if (true === is_null($name)) {
216
            $name = $this->mName;
217
        }
218
        $this->gName = $name;
219
        $this->gPlural = Str::plural($this->gName);
220
        $this->gCamel = Str::camel($this->gName);
221
        $this->gCamelPlural = Str::camel($this->gPlural);
222
        $this->gSnake = Str::snake($this->gName);
223
        $this->gSnakePlural = Str::snake($this->gPlural);
224
        $this->gDashed = str_replace('_', '-', Str::snake($this->gSnake));
225
        $this->gDashedPlural = str_replace('_', '-', Str::snake($this->gSnakePlural));
226
        $this->gSlash = str_replace('_', '/', Str::snake($this->gSnake));
227
        $this->gSlashPlural = str_replace('_', '/', Str::snake($this->gSnakePlural));
228
        $this->gHuman = Str::title(str_replace('_', ' ', Str::snake($this->gSnake)));
229
        $this->gHumanPlural = Str::title(str_replace('_', ' ', Str::snake($this->gSnakePlural)));
230
    }
231
232
    /**
233
     * Load Dynamic GraphQL Variables.
234
     *
235
     * @param Data $commandData Command Data.
236
     *
237
     * @return Data
238
     */
239
    public function loadDynamicGraphQLVariables(Data &$commandData)
240
    {
241
        $commandData->addDynamicVariable('$GRAPHQL_NAME$', $this->gName);
242
        $commandData->addDynamicVariable('$GRAPHQL_NAME_CAMEL$', $this->gCamel);
243
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL$', $this->gPlural);
244
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_CAMEL$', $this->gCamelPlural);
245
        $commandData->addDynamicVariable('$GRAPHQL_NAME_SNAKE$', $this->gSnake);
246
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SNAKE$', $this->gSnakePlural);
247
        $commandData->addDynamicVariable('$GRAPHQL_NAME_DASHED$', $this->gDashed);
248
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_DASHED$', $this->gDashedPlural);
249
        $commandData->addDynamicVariable('$GRAPHQL_NAME_SLASH$', $this->gSlash);
250
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SLASH$', $this->gSlashPlural);
251
        $commandData->addDynamicVariable('$GRAPHQL_NAME_HUMAN$', $this->gHuman);
252
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_HUMAN$', $this->gHumanPlural);
253
254
        return $commandData;
255
    }
256
257
    /**
258
     * Prepare Options.
259
     *
260
     * @param Data $commandData Command Data.
261
     *
262
     * @return void
263
     */
264
    public function prepareOptions(Data &$commandData)
265
    {
266
        foreach (self::$availableOptions as $option) {
267
            $this->options[$option] = $commandData->commandObj->option($option);
268
        }
269
270
        if (true === isset($options['fromTable']) && true === $this->options['fromTable']) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $options seems to never exist and therefore isset should always be false.
Loading history...
271
            if (false === $this->options['tableName']) {
272
                $commandData->commandError('tableName required with fromTable option.');
273
                exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
274
            }
275
        }
276
277
        if (true === empty($this->options['save'])) {
278
            $this->options['save'] = config('infyom.laravel_generator.options.save_schema_file', true);
279
        }
280
281
        if (true === empty($this->options['vue'])) {
282
            $this->options['vue'] = config('pwweb.artomator.options.vue_files', false);
283
        }
284
285
        if (true === empty($this->options['localized'])) {
286
            $this->options['localized'] = config('infyom.laravel_generator.options.localized', false);
287
        }
288
289
        if (true === $this->options['localized']) {
290
            $commandData->getTemplatesManager()->setUseLocale(true);
291
        }
292
293
        $this->options['softDelete'] = config('infyom.laravel_generator.options.softDelete', false);
294
        $this->options['repositoryPattern'] = config('infyom.laravel_generator.options.repository_pattern', true);
295
        $this->options['resources'] = config('infyom.laravel_generator.options.resources', true);
296
        if (false === empty($this->options['skip'])) {
297
            $this->options['skip'] = array_map('trim', explode(',', $this->options['skip']));
298
        }
299
300
        if (false === empty($this->options['datatables'])) {
301
            if ('true' === strtolower($this->options['datatables'])) {
302
                $this->addOns['datatables'] = true;
303
            } else {
304
                $this->addOns['datatables'] = false;
305
            }
306
        }
307
    }
308
}
309