Passed
Push — master ( 1fb286...0673bd )
by Richard
04:39 queued 11s
created

GeneratorConfig::prepareGraphQLNames()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 14
rs 9.8666
cc 2
nc 1
nop 0
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
    /* Path variables */
12
    public $pathGraphQL;
13
14
    /* Model Names */
15
    public $gName;
16
    public $gPlural;
17
    public $gCamel;
18
    public $gCamelPlural;
19
    public $gSnake;
20
    public $gSnakePlural;
21
    public $gDashed;
22
    public $gDashedPlural;
23
    public $gSlash;
24
    public $gSlashPlural;
25
    public $gHuman;
26
    public $gHumanPlural;
27
28
    public function init(Data &$commandData, $options = null)
29
    {
30
        parent::$availableOptions[] = 'gqlName';
31
        parent::init($commandData, $options);
32
    }
33
34
    public function loadPaths()
35
    {
36
        parent::loadPaths();
37
38
        $this->pathGraphQL = config('lighthouse.schema.register', base_path('graphql/schema.graphql'));
39
    }
40
41
    public function loadDynamicVariables(Data &$commandData)
42
    {
43
        parent::loadDynamicVariables($commandData);
44
        $commandData->addDynamicVariable('$LICENSE_PACKAGE$', config('pwweb.artomator.license.package'));
45
        $commandData->addDynamicVariable('$LICENSE_AUTHORS$', license_authors(config('pwweb.artomator.license.authors')));
46
        $commandData->addDynamicVariable('$LICENSE_COPYRIGHT$', config('pwweb.artomator.license.copyright'));
47
        $commandData->addDynamicVariable('$LICENSE$', config('pwweb.artomator.license.license'));
48
        $commandData->addDynamicVariable('$NAMESPACE_GRAPHQL_MODEL$', str_replace('\\', '\\\\', $this->nsModel));
49
        $this->prepareGraphQLNames();
50
51
        $commandData->addDynamicVariable('$GRAPHQL_NAME$', $this->gName);
52
        $commandData->addDynamicVariable('$GRAPHQL_NAME_CAMEL$', $this->gCamel);
53
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL$', $this->gPlural);
54
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_CAMEL$', $this->gCamelPlural);
55
        $commandData->addDynamicVariable('$GRAPHQL_NAME_SNAKE$', $this->gSnake);
56
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SNAKE$', $this->gSnakePlural);
57
        $commandData->addDynamicVariable('$GRAPHQL_NAME_DASHED$', $this->gDashed);
58
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_DASHED$', $this->gDashedPlural);
59
        $commandData->addDynamicVariable('$GRAPHQL_NAME_SLASH$', $this->gSlash);
60
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SLASH$', $this->gSlashPlural);
61
        $commandData->addDynamicVariable('$GRAPHQL_NAME_HUMAN$', $this->gHuman);
62
        $commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_HUMAN$', $this->gHumanPlural);
63
64
        return $commandData;
65
    }
66
67
    public function prepareGraphQLNames()
68
    {
69
        $this->gName = ($this->getOption('gqlName')?: $this->mName);
70
        $this->gPlural = Str::plural($this->gName);
71
        $this->gCamel = Str::camel($this->gName);
72
        $this->gCamelPlural = Str::camel($this->gPlural);
73
        $this->gSnake = Str::snake($this->gName);
74
        $this->gSnakePlural = Str::snake($this->gPlural);
75
        $this->gDashed = str_replace('_', '-', Str::snake($this->gSnake));
76
        $this->gDashedPlural = str_replace('_', '-', Str::snake($this->gSnakePlural));
77
        $this->gSlash = str_replace('_', '/', Str::snake($this->gSnake));
78
        $this->gSlashPlural = str_replace('_', '/', Str::snake($this->gSnakePlural));
79
        $this->gHuman = Str::title(str_replace('_', ' ', Str::snake($this->gSnake)));
80
        $this->gHumanPlural = Str::title(str_replace('_', ' ', Str::snake($this->gSnakePlural)));
81
    }
82
}
83