ViewsGeneratorCommand::getOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 3
c 3
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PWWEB\Artomator\Commands\Scaffold;
4
5
use InfyOm\Generator\Commands\Scaffold\ViewsGeneratorCommand as Base;
6
use PWWEB\Artomator\Common\CommandData;
7
use PWWEB\Artomator\Generators\Scaffold\ViewGenerator;
8
use PWWEB\Artomator\Generators\Scaffold\VueGenerator;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class ViewsGeneratorCommand extends Base
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'artomator.scaffold:views';
19
20
    /**
21
     * Create a new command instance.
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
27
        $this->commandData = new CommandData($this, CommandData::$COMMAND_TYPE_SCAFFOLD);
28
    }
29
30
    /**
31
     * Execute the command.
32
     *
33
     * @return void
34
     */
35
    public function handle()
36
    {
37
        $this->commandData->modelName = $this->argument('model');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->argument('model') can also be of type string[]. However, the property $modelName is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
38
39
        $this->commandData->initCommandData();
40
        $this->commandData->getFields();
41
42
        if (false === $this->commandData->getOption('vue')) {
43
            $viewGenerator = new ViewGenerator($this->commandData);
44
            $viewGenerator->generate();
45
        } else {
46
            $vueGenerator = new VueGenerator($this->commandData);
47
            $vueGenerator->generate();
48
        }
49
50
        $this->performPostActions();
51
    }
52
53
    /**
54
     * Get the console command options.
55
     *
56
     * @return array
57
     */
58
    public function getOptions()
59
    {
60
        return array_merge(
61
            parent::getOptions(),
62
            [
63
                ['vue', null, InputOption::VALUE_NONE, 'Generate Vuejs views rather than blade views'],
64
            ]
65
        );
66
    }
67
}
68