Passed
Push — master ( 617e52...ff4e9f )
by Arthur
35:51
created

TestMakeCommand::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Exceptions\Exception;
6
use Foundation\Generator\Abstracts\ClassGeneratorCommand;
7
use Foundation\Generator\Events\TestGeneratedEvent;
8
use Illuminate\Support\Str;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class TestMakeCommand extends ClassGeneratorCommand
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'larapi:make:test';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Create a new test class for the specified module.';
26
27
    /**
28
     * The name of the generated resource.
29
     *
30
     * @var string
31
     */
32
    protected $generatorName = 'test';
33
34
    /**
35
     * The file path.
36
     *
37
     * @var string
38
     */
39
    protected $filePath = '/Tests';
40
41
    /**
42
     * The event that will fire when the file is created.
43
     *
44
     * @var string
45
     */
46
    protected $event = TestGeneratedEvent::class;
47
48
    protected $types = [
49
        "unit",
50
        "http",
51
        "service"
52
    ];
53
54 1
    protected function stubOptions(): array
55
    {
56
        return [
57 1
            'NAMESPACE' => $this->getClassNamespace(),
58 1
            'CLASS' => $this->getClassName(),
59 1
            'TYPE' => $this->getType(),
60 1
            'PLURAL_LOWER_MODULE' => strtolower(Str::plural($this->getModuleName()))
61
        ];
62
    }
63
64 1
    protected function getType(): string
65
    {
66 1
        return $this->getOption('type');
67
    }
68
69
    /**
70
     * @return string
71
     */
72 1
    protected function stubName(): string
73
    {
74 1
        $type = $this->getType();
75
76 1
        if (in_array($type, $this->types))
77 1
            return "test-" . $type . ".stub";
78
79
        throw new Exception("Test type not supported");
80
    }
81
82
    /**
83
     * Get the console command options.
84
     *
85
     * @return array
86
     */
87 110
    protected function setOptions(): array
88
    {
89
        return [
90 110
            ['type', $this->types, InputOption::VALUE_OPTIONAL, 'Indicates the type of the test.', $this->types[0]]
91
        ];
92
    }
93
94
    protected function handleTypeOption($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

94
    protected function handleTypeOption($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

94
    protected function handleTypeOption(/** @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

94
    protected function handleTypeOption($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...
95
    {
96
        return $this->anticipate('What is the type of the test?', $this->types, $default);
97
    }
98
}
99