Passed
Push — master ( 40ce26...965fb6 )
by Arthur
22:04
created

TransformerMakeCommand::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Core\Larapi;
6
use Foundation\Generator\Abstracts\AbstractGeneratorCommand;
7
use Foundation\Generator\Abstracts\ClassGeneratorCommand;
8
use Foundation\Generator\Events\TransformerGeneratedEvent;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class TransformerMakeCommand extends ClassGeneratorCommand
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'larapi:make:transformer';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Create a new transformer class for the specified module.';
26
27
    /**
28
     * The name of the generated resource.
29
     *
30
     * @var string
31
     */
32
    protected $generatorName = 'transformer';
33
34
    /**
35
     * The stub name.
36
     *
37
     * @var string
38
     */
39
    protected $stub = 'transformer.stub';
40
41
    /**
42
     * The file path.
43
     *
44
     * @var string
45
     */
46
    protected $filePath = '/Transformers';
47
48
    /**
49
     * The event that will fire when the file is created.
50
     *
51
     * @var string
52
     */
53
    protected $event = TransformerGeneratedEvent::class;
54
55
    protected function stubOptions(): array
56
    {
57
        return [
58
            'CLASS' => $this->getClassName(),
59
            'NAMESPACE' => $this->getClassNamespace(),
60
            'MODEL' => $this->getModelName(),
61
            "LOWER_MODEL" => strtolower($this->getModelName()),
62
            'MODEL_NAMESPACE' => $this->getModule()->getNamespace().'\\'.'Entities'.'\\'.$this->getModelName(),
63
        ];
64
    }
65
66
    /**
67
     * Get the console command options.
68
     *
69
     * @return array
70
     */
71
    protected function setOptions() :array
72
    {
73
        return [
74
            ['model', null, InputOption::VALUE_OPTIONAL, 'The Model name for the transformer.', null],
75
        ];
76
    }
77
78
    protected function getModelName(): string
79
    {
80
        return $this->getOption("model");
81
    }
82
83
    protected function handleModelOption(){
84
        return $this->anticipate('For what model would you like to generate a transformer?', Larapi::getModule($this->getModuleName())->getModels()->getAllPhpFileNamesWithoutExtension(), $this->getModuleName());
85
    }
86
}
87