GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RepositoryCommand::getOptions()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 27

Duplication

Lines 40
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
nc 1
nop 0
dl 40
loc 40
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Milkmeowo\Framework\Repository\Generators\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Milkmeowo\Framework\Repository\Generators\ModelGenerator;
10
use Milkmeowo\Framework\Repository\Generators\SeederGenerator;
11
use Milkmeowo\Framework\Repository\Generators\CriteriaGenerator;
12
use Milkmeowo\Framework\Repository\Generators\MigrationGenerator;
13
use Milkmeowo\Framework\Repository\Generators\RepositoryEloquentGenerator;
14
use Milkmeowo\Framework\Repository\Generators\RepositoryInterfaceGenerator;
15
use Milkmeowo\Framework\Repository\Generators\Exceptions\FileAlreadyExistsException;
16
17
class RepositoryCommand extends Command
18
{
19
    /**
20
     * The name of command.
21
     *
22
     * @var string
23
     */
24
    protected $name = 'starter:repository';
25
26
    /**
27
     * The description of command.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Create a new repository.';
32
33
    /**
34
     * The type of class being generated.
35
     *
36
     * @var string
37
     */
38
    protected $type = 'Repository';
39
40
    /**
41
     * @var Collection
42
     */
43
    protected $generators = null;
44
45
    /**
46
     * Execute the command.
47
     *
48
     * @return void
49
     */
50
    public function fire()
51
    {
52
        $this->generators = new Collection();
53
54
        $this->generators->push(new MigrationGenerator([
55
            'name'   => 'create_'.snake_case(str_plural($this->argument('name'))).'_table',
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, str_plural() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
56
            'fields' => $this->option('fillable'),
57
            'force'  => $this->option('force'),
58
        ]));
59
60
        $modelGenerator = new ModelGenerator([
61
            'name'     => $this->argument('name'),
62
            'fillable' => $this->option('fillable'),
63
            'force'    => $this->option('force'),
64
        ]);
65
66
        $this->generators->push($modelGenerator);
67
68
        $this->generators->push(new SeederGenerator([
69
            'name'  => $this->argument('name'),
70
            'force' => $this->option('force'),
71
        ]));
72
73
        $this->generators->push(new RepositoryInterfaceGenerator([
74
            'name'  => $this->argument('name'),
75
            'force' => $this->option('force'),
76
        ]));
77
78
        //$this->generators->push(new CriteriaGenerator([
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
        //    'name'  => $this->argument('name'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
        //    'force' => $this->option('force'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
        //]));
82
83
        foreach ($this->generators as $generator) {
84
            $generator->run();
85
        }
86
87
        $model = $modelGenerator->getRootNamespace().'\\'.$modelGenerator->getName();
88
        $model = str_replace([
89
            '\\',
90
            '/',
91
        ], '\\', $model);
92
93
        try {
94
            (new RepositoryEloquentGenerator([
95
                'name'      => $this->argument('name'),
96
                'rules'     => $this->option('rules'),
97
                'validator' => $this->option('validator'),
98
                'presenter' => $this->option('presenter'),
99
                'force'     => $this->option('force'),
100
                'model'     => $model,
101
            ]))->run();
102
            $this->info('Repository created successfully.');
103
        } catch (FileAlreadyExistsException $e) {
104
            $this->error($this->type.' already exists!');
105
106
            return false;
107
        }
108
    }
109
110
    /**
111
     * The array of command arguments.
112
     *
113
     * @return array
114
     */
115
    public function getArguments()
116
    {
117
        return [
118
            [
119
                'name',
120
                InputArgument::REQUIRED,
121
                'The name of class being generated.',
122
                null,
123
            ],
124
        ];
125
    }
126
127
    /**
128
     * The array of command options.
129
     *
130
     * @return array
131
     */
132 View Code Duplication
    public function getOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134
        return [
135
            [
136
                'fillable',
137
                null,
138
                InputOption::VALUE_OPTIONAL,
139
                'The fillable attributes.',
140
                null,
141
            ],
142
            [
143
                'rules',
144
                null,
145
                InputOption::VALUE_OPTIONAL,
146
                'The rules of validation attributes.',
147
                null,
148
            ],
149
            [
150
                'validator',
151
                null,
152
                InputOption::VALUE_OPTIONAL,
153
                'Adds validator reference to the repository.',
154
                null,
155
            ],
156
            [
157
                'presenter',
158
                null,
159
                InputOption::VALUE_OPTIONAL,
160
                'Adds presenter reference to the repository.',
161
                null,
162
            ],
163
            [
164
                'force',
165
                'f',
166
                InputOption::VALUE_NONE,
167
                'Force the creation if file already exists.',
168
                null,
169
            ],
170
        ];
171
    }
172
}
173