ValidatorCommand::fire()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 3
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Yeelight\Generators\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputOption;
7
use Yeelight\Generators\FileAlreadyExistsException;
8
use Yeelight\Generators\ValidatorGenerator;
9
10
/**
11
 * Class ValidatorCommand
12
 *
13
 * @category Yeelight
14
 *
15
 * @package Yeelight\Generators\Commands
16
 *
17
 * @author Sheldon Lee <[email protected]>
18
 *
19
 * @license https://opensource.org/licenses/MIT MIT
20
 *
21
 * @link https://www.yeelight.com
22
 */
23
class ValidatorCommand extends CommandBase
24
{
25
    /**
26
     * The name of command.
27
     *
28
     * @var string
29
     */
30
    protected $name = 'yl:validator';
31
32
    /**
33
     * The description of command.
34
     *
35
     * @var string
36
     */
37
    protected $description = 'Create a new validator.';
38
39
    /**
40
     * The type of class being generated.
41
     *
42
     * @var string
43
     */
44
    protected $type = 'Validator';
45
46
    /**
47
     * Execute the command.
48
     *
49
     * @return bool | void
50
     */
51
    public function fire()
52
    {
53
        try {
54
            (new ValidatorGenerator(
55
                [
56
                    'name' => $this->argument('name'),
57
                    'rules' => $this->option('rules'),
58
                    'force' => $this->option('force'),
59
                ]
60
            ))->run();
61
            $this->info('Validator created successfully.');
62
        } catch (FileAlreadyExistsException $e) {
63
            $this->error($this->type.' already exists!');
64
65
            return false;
66
        }
67
    }
68
69
    /**
70
     * The array of command arguments.
71
     *
72
     * @return array
73
     */
74
    public function getArguments()
75
    {
76
        return [
77
            [
78
                'name',
79
                InputArgument::REQUIRED,
80
                'The name of model for which the validator is being generated.',
81
                null,
82
            ],
83
        ];
84
    }
85
86
    /**
87
     * The array of command options.
88
     *
89
     * @return array
90
     */
91
    public function getOptions()
92
    {
93
        return [
94
            [
95
                'rules',
96
                null,
97
                InputOption::VALUE_OPTIONAL,
98
                'The rules of validation attributes.',
99
                null,
100
            ],
101
            [
102
                'force',
103
                'f',
104
                InputOption::VALUE_NONE,
105
                'Force the creation if file already exists.',
106
                null,
107
            ],
108
        ];
109
    }
110
}
111