Passed
Push — master ( ff4e9f...624a9a )
by Arthur
35:46
created

RouteMakeCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 76
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A handleVersioningOption() 0 2 1
A setOptions() 0 4 1
A afterGeneration() 0 3 1
A getVersion() 0 2 1
A stubOptions() 0 6 1
A getFileName() 0 3 1
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Generator\Abstracts\AbstractGeneratorCommand;
6
use Foundation\Generator\Abstracts\FileGeneratorCommand;
7
use Foundation\Generator\Events\RouteGeneratedEvent;
8
use Illuminate\Support\Str;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputOption;
11
12
class RouteMakeCommand extends FileGeneratorCommand
13
{
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'larapi:make:route';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new route file for the specified module';
27
28
    /**
29
     * The name of the generated resource.
30
     *
31
     * @var string
32
     */
33
    protected $generatorName = 'route';
34
35
    /**
36
     * The stub name.
37
     *
38
     * @var string
39
     */
40
    protected $stub = 'route.stub';
41
42
    /**
43
     * The file path.
44
     *
45
     * @var string
46
     */
47
    protected $filePath = '/Routes';
48
49
    /**
50
     * The event that will fire when the file is created.
51
     *
52
     * @var string
53
     */
54
    protected $event = RouteGeneratedEvent::class;
55
56 2
    protected function stubOptions(): array
57
    {
58
        return [
59 2
            'MODULE_NAME' => ucfirst($this->getModuleName()),
60 2
            'CAPS_MODULE_NAME' => strtoupper($this->getModuleName()),
61 2
            'VERSION' => $this->getVersion()
62
        ];
63
    }
64
65 2
    protected function getVersion() :string {
66 2
        return $this->getOption('versioning');
67
    }
68
69 2
    protected function afterGeneration(): void
70
    {
71 2
        $this->info("Don't forget to add permissions to the Permission model!");
72 2
    }
73
74
    protected function handleVersioningOption($shortcut, $type, $question, $default){
0 ignored issues
show
Unused Code introduced by
The parameter $question is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    protected function handleVersioningOption($shortcut, $type, /** @scrutinizer ignore-unused */ $question, $default){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $shortcut is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    protected function handleVersioningOption(/** @scrutinizer ignore-unused */ $shortcut, $type, $question, $default){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    protected function handleVersioningOption($shortcut, /** @scrutinizer ignore-unused */ $type, $question, $default){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
        return $this->anticipate('What is the version of the route?',['v1','v2','v3','v4','v5'],$default);
76
    }
77
78 112
    protected function setOptions(): array
79
    {
80
        return [
81 112
            ['versioning', null, InputOption::VALUE_OPTIONAL, 'The route version', 'v1'],
82
        ];
83
    }
84
85 2
    protected function getFileName() :string
86
    {
87 2
        return strtolower(Str::plural($this->getModuleName())).'.'.$this->getVersion() . '.php';
88
    }
89
90
}
91