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

FactoryMakeCommand::handleCommandOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 2
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Core\Larapi;
6
use Foundation\Generator\Abstracts\FileGeneratorCommand;
7
use Foundation\Generator\Events\FactoryGeneratedEvent;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class FactoryMakeCommand extends FileGeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'larapi:make:factory';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new model factory for the specified module.';
25
26
    /**
27
     * The name of the generated resource.
28
     *
29
     * @var string
30
     */
31
    protected $generatorName = 'factory';
32
33
    /**
34
     * The stub name.
35
     *
36
     * @var string
37
     */
38
    protected $stub = 'factory.stub';
39
40
    /**
41
     * The file path.
42
     *
43
     * @var string
44
     */
45 1
    protected $filePath = '/Database/factories';
46
47
    /**
48 1
     * The event that will fire when the file is created.
49 1
     *
50
     * @var string
51
     */
52 1
    protected $event = FactoryGeneratedEvent::class;
53
54 1
    protected function getClassName(): string
55
    {
56
        return $this->getModelName() . 'Factory';
57 1
    }
58
59
    protected function stubOptions(): array
60 1
    {
61 1
        return [
62 1
            'CLASS' => $this->getClassName(),
63
            'MODEL' => $this->getModelName(),
64
            'MODEL_NAMESPACE' => $this->getModule()->getNamespace() . '\\' . 'Entities' . '\\' . $this->getModelName(),
65
        ];
66
    }
67
68
    /**
69
     * Get the console command options.
70
     *
71 87
     * @return array
72
     */
73
    protected function setOptions(): array
74 87
    {
75
        return [
76
            ['model', null, InputOption::VALUE_OPTIONAL, 'The Model name for the factory.', null],
77
        ];
78
    }
79
80
    protected function handleModelOption($shortcut, $type, $question, $default)
0 ignored issues
show
Unused Code introduced by
The parameter $default 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

80
    protected function handleModelOption($shortcut, $type, $question, /** @scrutinizer ignore-unused */ $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

80
    protected function handleModelOption(/** @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

80
    protected function handleModelOption($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 $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

80
    protected function handleModelOption($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...
81
    {
82
        return $this->anticipate('For what model would you like to generate a factory?', Larapi::getModule($this->getModuleName())->getModels()->getAllPhpFileNamesWithoutExtension(), Larapi::getModule($this->getModuleName())->getModels()->getAllPhpFileNamesWithoutExtension()[0] ?? "");
83
    }
84
85
    protected function getModelName() :string
86
    {
87
        return $this->getOption('model');
88
    }
89
90
    protected function getFileName(): string
91
    {
92
        return $this->getClassName().'.php';
93
    }
94
}
95