Passed
Push — feature/lg ( 1bf2ef...8f3d7e )
by Richard
03:59
created

RollbackGeneratorCommand::handle()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 28
c 3
b 0
f 0
dl 0
loc 44
rs 9.472
cc 4
nc 6
nop 0
1
<?php
2
3
namespace PWWEB\Artomator\Commands;
4
5
use Illuminate\Console\Command;
6
use InfyOm\Generator\Commands\RollbackGeneratorCommand as Base;
7
use InfyOm\Generator\Generators\Scaffold\ViewGenerator;
8
use PWWEB\Artomator\Common\CommandData;
9
use PWWEB\Artomator\Generators\GraphQL\GraphQLMutationGenerator;
10
use PWWEB\Artomator\Generators\GraphQL\GraphQLQueryGenerator;
11
use PWWEB\Artomator\Generators\GraphQL\GraphQLSubscriptionGenerator;
12
use PWWEB\Artomator\Generators\GraphQL\GraphQLTypeGenerator;
13
14
class RollbackGeneratorCommand extends Base
15
{
16
    /**
17
     * The command Data.
18
     *
19
     * @var CommandData
20
     */
21
    public $commandData;
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'artomator:rollback';
28
29
    /**
30
     * @var Composer
0 ignored issues
show
Bug introduced by
The type PWWEB\Artomator\Commands\Composer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    public $composer;
33
34
    /**
35
     * Create a new command instance.
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
41
        $this->composer = app()['composer'];
0 ignored issues
show
Documentation Bug introduced by
It seems like app()['composer'] of type Illuminate\Support\Composer is incompatible with the declared type PWWEB\Artomator\Commands\Composer of property $composer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42
    }
43
44
    /**
45
     * Execute the command.
46
     *
47
     * @return void
48
     */
49
    public function handle()
50
    {
51
        if (! in_array($this->argument('type'), [
52
            CommandData::$COMMAND_TYPE_API,
53
            CommandData::$COMMAND_TYPE_SCAFFOLD,
54
            CommandData::$COMMAND_TYPE_API_SCAFFOLD,
55
            CommandData::$COMMAND_TYPE_GRAPHQL,
56
            CommandData::$COMMAND_TYPE_GRAPHQL_SCAFFOLD,
57
        ])) {
58
            $this->error('invalid rollback type');
59
        }
60
61
        $this->commandData = new CommandData($this, $this->argument('type'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('type') can also be of type string[]; however, parameter $commandType of PWWEB\Artomator\Common\CommandData::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $this->commandData = new CommandData($this, /** @scrutinizer ignore-type */ $this->argument('type'));
Loading history...
62
        $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...
63
64
        $this->commandData->config->init($this->commandData, ['tableName', 'prefix', 'plural', 'views']);
65
66
        $views = $this->commandData->getOption('views');
67
        if (! empty($views)) {
68
            $views = explode(',', $views);
69
            $viewGenerator = new ViewGenerator($this->commandData);
70
            $viewGenerator->rollback($views);
71
72
            $this->info('Generating autoload files');
73
            $this->composer->dumpOptimized();
74
75
            return;
76
        }
77
78
        $typeGenerator = new GraphQLTypeGenerator($this->commandData);
79
        $typeGenerator->rollback();
80
81
        $queryGenerator = new GraphQLQueryGenerator($this->commandData);
82
        $queryGenerator->rollback();
83
84
        $mutationGenerator = new GraphQLMutationGenerator($this->commandData);
85
        $mutationGenerator->rollback();
86
87
        if (config('pwweb.artomator.options.subscription')) {
88
            $subscriptionGenerator = new GraphQLSubscriptionGenerator($this->commandData);
89
            $subscriptionGenerator->rollback();
90
        }
91
92
        parent::handle();
93
    }
94
}
95