CommandValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 21 5
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Laravel\Commands;
4
5
use Formularium\Factory\ValidatorFactory;
6
use Formularium\Exception\Exception;
7
use Illuminate\Console\Command;
8
9
class CommandValidator extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'formularium:validator
17
        {name : The validator name}
18
        {--namespace= : the class namespace. Defaults to "\\App\\Formularium\\Validators"}
19
        {--path= : path to save the file. Defaults to "basepath("app/Formularium/Validators") }
20
        {--test-path= : path to save the file. Defaults to "basepath("tests/Unit") }
21
    ';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Creates scaffolding using Modelarium';
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @return void
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $code = ValidatorFactory::generate(
48
            // @phpstan-ignore-next-line
49
            (string)$this->argument('name'),
50
            // @phpstan-ignore-next-line
51
            $this->option('namespace') ? (string)$this->option('namespace') : 'App\\Formularium\\Validator'
52
        );
53
54
        try {
55
            $retval = ValidatorFactory::generateFile(
56
                $code,
57
                $this->option('path') ? $this->option('path') : /** @scrutinizer ignore-call */ base_path('app/Formularium/Validator'),
58
                $this->option('test-path') ? $this->option('test-path') : /** @scrutinizer ignore-call */ base_path('tests/Unit/')
59
            );
60
61
            $this->line($retval['code']);
62
            $this->line($retval['test']);
63
            $this->info('Finished. You might want to run `composer dump-autoload`');
64
        } catch (Exception $e) {
65
            $this->error($e->getMessage());
66
        }
67
    }
68
}
69