Completed
Push — master ( 15e02a...758c52 )
by Nicolas
05:13
created

GenerateRouteProviderCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 73
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 6 1
A getTemplateContents() 0 14 1
A getDestinationFilePath() 0 8 1
A getFileName() 0 4 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Pingpong\Support\Stub;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class GenerateRouteProviderCommand extends GeneratorCommand
10
{
11
    use ModuleCommandTrait;
12
13
    protected $argumentName = 'module';
14
    /**
15
     * The command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'module:route-provider';
20
21
    /**
22
     * The command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Generate a new route service provider for the specified module.';
27
28
    /**
29
     * The command arguments.
30
     *
31
     * @return array
32
     */
33 16
    protected function getArguments()
34
    {
35
        return array(
36 16
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
37 16
        );
38
    }
39
40
    /**
41
     * Get template contents.
42
     *
43
     * @return string
44
     */
45 2
    protected function getTemplateContents()
46
    {
47 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
48
49 2
        return (new Stub('/route-provider.stub', [
50 2
            'NAMESPACE'         => $this->getClassNamespace($module),
51 2
            'CLASS'             => $this->getClass(),
52 2
            'LOWER_NAME'        => $module->getLowerName(),
53 2
            'MODULE'            => $this->getModuleName(),
54 2
            'NAME'              => $this->getFileName(),
55 2
            'STUDLY_NAME'       => $module->getStudlyName(),
56 2
            'MODULE_NAMESPACE'  => $this->laravel['modules']->config('namespace'),
57 2
        ]))->render();
58
    }
59
60
    /**
61
     * Get the destination file path.
62
     *
63
     * @return string
64
     */
65 2
    protected function getDestinationFilePath()
66
    {
67 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
68
69 2
        $generatorPath = $this->laravel['modules']->config('paths.generator.provider');
70
71 2
        return $path.$generatorPath.'/'.$this->getFileName().'.php';
72
    }
73
74
    /**
75
     * @return string
76
     */
77 2
    private function getFileName()
78
    {
79 2
        return 'RouteServiceProvider';
80
    }
81
}
82