Passed
Push — master ( 590453...ad5a85 )
by Arthur
24:49
created

TestMakeCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 85
rs 10
c 0
b 0
f 0
ccs 0
cts 29
cp 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 4 1
A handleTypeOption() 0 3 1
A stubOptions() 0 6 1
A stubName() 0 8 2
A getType() 0 3 1
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 Symfony\Component\Console\Input\InputOption;
9
10
class TestMakeCommand extends ClassGeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'larapi:make:test';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new test class for the specified module.';
25
26
    /**
27
     * The name of the generated resource.
28
     *
29
     * @var string
30
     */
31
    protected $generatorName = 'test';
32
33
    /**
34
     * The file path.
35
     *
36
     * @var string
37
     */
38
    protected $filePath = '/Tests';
39
40
    /**
41
     * The event that will fire when the file is created.
42
     *
43
     * @var string
44
     */
45
    protected $event = TestGeneratedEvent::class;
46
47
    protected $types = [
48
        "unit",
49
        "http",
50
        "service"
51
    ];
52
53
    protected function stubOptions(): array
54
    {
55
        return [
56
            'NAMESPACE' => $this->getClassNamespace(),
57
            'CLASS' => $this->getClassName(),
58
            'TYPE' => $this->getType()
59
        ];
60
    }
61
62
    protected function getType(): string
63
    {
64
        return $this->getOption('type');
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    protected function stubName(): string
71
    {
72
        $type = $this->getType();
73
74
        if (in_array($type, $this->types))
75
            return "$type-test.stub";
76
77
        throw new Exception("Test type not supported");
78
    }
79
80
    /**
81
     * Get the console command options.
82
     *
83
     * @return array
84
     */
85
    protected function setOptions(): array
86
    {
87
        return [
88
            ['type', $this->types, InputOption::VALUE_OPTIONAL, 'Indicates the type of the test.', $this->types[0]]
89
        ];
90
    }
91
92
    protected function handleTypeOption($shortcut, $type, $question, $default)
0 ignored issues
show
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

92
    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...
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

92
    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 $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

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