RollbackGeneratorCommand::handle()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 51
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 31
c 4
b 0
f 0
dl 0
loc 51
rs 9.424
cc 4
nc 6
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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