Passed
Push — master ( 9de3df...49c81a )
by Richard
11:22 queued 11s
created

RollbackGeneratorCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 34
c 4
b 0
f 0
dl 0
loc 79
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 44 4
A __construct() 0 5 1
1
<?php
2
3
namespace PWWEB\Artomator\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Composer;
7
use InfyOm\Generator\Commands\RollbackGeneratorCommand as Base;
8
use InfyOm\Generator\Generators\Scaffold\ViewGenerator;
9
use PWWEB\Artomator\Common\CommandData;
10
use PWWEB\Artomator\Generators\GraphQL\GraphQLMutationGenerator;
11
use PWWEB\Artomator\Generators\GraphQL\GraphQLQueryGenerator;
12
use PWWEB\Artomator\Generators\GraphQL\GraphQLSubscriptionGenerator;
13
use PWWEB\Artomator\Generators\GraphQL\GraphQLTypeGenerator;
14
15
class RollbackGeneratorCommand extends Base
16
{
17
    /**
18
     * The command Data.
19
     *
20
     * @var CommandData
21
     */
22
    public $commandData;
23
    /**
24
     * The console command name.
25
     *
26
     * @var string
27
     */
28
    protected $name = 'artomator:rollback';
29
30
    /**
31
     * @var Composer
32
     */
33
    public $composer;
34
35
    /**
36
     * Create a new command instance.
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
42
        $this->composer = app()['composer'];
43
    }
44
45
    /**
46
     * Execute the command.
47
     *
48
     * @return void
49
     */
50
    public function handle()
51
    {
52
        if (false === in_array($this->argument('type'), [
53
            CommandData::$COMMAND_TYPE_API,
54
            CommandData::$COMMAND_TYPE_SCAFFOLD,
55
            CommandData::$COMMAND_TYPE_API_SCAFFOLD,
56
            CommandData::$COMMAND_TYPE_GRAPHQL,
57
            CommandData::$COMMAND_TYPE_GRAPHQL_SCAFFOLD,
58
        ])) {
59
            $this->error('invalid rollback type');
60
        }
61
62
        $this->commandData = new CommandData($this, $this->argument('type'));
63
        $this->commandData->config->mName = $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...
64
65
        $this->commandData->config->init($this->commandData, ['tableName', 'prefix', 'plural', 'views']);
66
67
        $views = $this->commandData->getOption('views');
68
        if (false === empty($views)) {
69
            $views = explode(',', $views);
70
            $viewGenerator = new ViewGenerator($this->commandData);
71
            $viewGenerator->rollback($views);
72
73
            $this->info('Generating autoload files');
74
            $this->composer->dumpOptimized();
75
76
            return;
77
        }
78
79
        $typeGenerator = new GraphQLTypeGenerator($this->commandData);
80
        $typeGenerator->rollback();
81
82
        $queryGenerator = new GraphQLQueryGenerator($this->commandData);
83
        $queryGenerator->rollback();
84
85
        $mutationGenerator = new GraphQLMutationGenerator($this->commandData);
86
        $mutationGenerator->rollback();
87
88
        if (config('pwweb.artomator.options.subscription')) {
89
            $subscriptionGenerator = new GraphQLSubscriptionGenerator($this->commandData);
90
            $subscriptionGenerator->rollback();
91
        }
92
93
        parent::handle();
94
    }
95
}
96