Passed
Push — feature/lg ( 3c06af...b2e7fb )
by Richard
03:07
created

ScaffoldGeneratorCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 2
b 0
f 0
dl 0
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIsThereAnyDataToGenerate() 0 4 2
A getOptions() 0 3 1
A __construct() 0 5 1
A getArguments() 0 3 1
A handle() 0 12 2
1
<?php
2
3
namespace PWWEB\Artomator\Commands\Scaffold;
4
5
use PWWEB\Artomator\Commands\BaseCommand;
6
use PWWEB\Artomator\Common\CommandData;
7
8
class ScaffoldGeneratorCommand extends BaseCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'artomator:scaffold';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a full CRUD views for given model';
23
24
    /**
25
     * Create a new command instance.
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
31
        $this->commandData = new CommandData($this, CommandData::$COMMAND_TYPE_SCAFFOLD);
32
    }
33
34
    /**
35
     * Execute the command.
36
     *
37
     * @return void
38
     */
39
    public function handle()
40
    {
41
        parent::handle();
42
43
        if ($this->checkIsThereAnyDataToGenerate()) {
44
            $this->generateCommonItems();
45
46
            $this->generateScaffoldItems();
47
48
            $this->performPostActionsWithMigration();
49
        } else {
50
            $this->commandData->commandInfo('There are not enough input fields for scaffold generation.');
51
        }
52
    }
53
54
    /**
55
     * Get the console command options.
56
     *
57
     * @return array
58
     */
59
    public function getOptions()
60
    {
61
        return array_merge(parent::getOptions(), []);
62
    }
63
64
    /**
65
     * Get the console command arguments.
66
     *
67
     * @return array
68
     */
69
    protected function getArguments()
70
    {
71
        return array_merge(parent::getArguments(), []);
72
    }
73
74
    /**
75
     * Check if there is anything to generate.
76
     *
77
     * @return bool
78
     */
79
    protected function checkIsThereAnyDataToGenerate()
80
    {
81
        if (count($this->commandData->fields) > 1) {
82
            return true;
83
        }
84
    }
85
}
86