GenerateProviderCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 103
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 7 1
A getOptions() 0 6 1
A getTemplateContents() 0 19 2
A getDestinationFilePath() 0 8 1
A getFileName() 0 4 1
A getDefaultNamespace() 0 4 1
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Support\Str;
6
use Consigliere\Components\Support\Stub;
7
use Consigliere\Components\Traits\ComponentCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class GenerateProviderCommand extends Command
12
{
13
    use ComponentCommandTrait;
14
15
    /**
16
     * The name of argument name.
17
     *
18
     * @var string
19
     */
20
    protected $argumentName = 'name';
21
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'component:make-provider';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Generate a new service provider for the specified component.';
35
36
    /**
37
     * Get the console command arguments.
38
     *
39
     * @return array
40
     */
41
    protected function getArguments()
42
    {
43
        return [
44
            ['name', InputArgument::REQUIRED, 'The service provider name.'],
45
            ['component', InputArgument::OPTIONAL, 'The name of component will be used.'],
46
        ];
47
    }
48
49
    /**
50
     * Get the console command options.
51
     *
52
     * @return array
53
     */
54
    protected function getOptions()
55
    {
56
        return [
57
            ['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null],
58
        ];
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    protected function getTemplateContents()
65
    {
66
        $stub = $this->option('master') ? 'scaffold/provider' : 'provider';
67
68
        $component = $this->laravel['components']->findOrFail($this->getComponentName());
69
70
        return (new Stub('/' . $stub . '.stub', [
71
            'NAMESPACE'           => $this->getClassNamespace($component),
72
            'CLASS'               => $this->getClass(),
73
            'LOWER_NAME'          => $component->getLowerName(),
74
            'COMPONENT'           => $this->getComponentName(),
75
            'NAME'                => $this->getFileName(),
76
            'STUDLY_NAME'         => $component->getStudlyName(),
77
            'COMPONENT_NAMESPACE' => $this->laravel['components']->config('namespace'),
78
            'PATH_VIEWS'          => $this->laravel['config']->get('components.paths.generator.views'),
79
            'PATH_LANG'           => $this->laravel['config']->get('components.paths.generator.lang'),
80
            'PATH_CONFIG'         => $this->laravel['config']->get('components.paths.generator.config'),
81
        ]))->render();
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    protected function getDestinationFilePath()
88
    {
89
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
90
91
        $generatorPath = $this->laravel['components']->config('paths.generator.provider');
92
93
        return $path . $generatorPath . '/' . $this->getFileName() . '.php';
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    private function getFileName()
100
    {
101
        return Str::studly($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
102
    }
103
104
    /**
105
     * Get default namespace.
106
     *
107
     * @return string
108
     */
109
    public function getDefaultNamespace()
110
    {
111
        return 'Providers';
112
    }
113
}
114