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.

ModuleMigrateRollbackCommand::fire()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 16
rs 9.2
cc 4
eloc 9
nc 4
nop 0
1
<?php
2
3
namespace Caffeinated\Modules\Console\Commands;
4
5
use Caffeinated\Modules\Modules;
6
use Caffeinated\Modules\Traits\MigrationTrait;
7
use Illuminate\Console\ConfirmableTrait;
8
use Illuminate\Console\Command;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Input\InputArgument;
11
12
class ModuleMigrateRollbackCommand extends Command
13
{
14
    use MigrationTrait, ConfirmableTrait;
15
16
    /**
17
     * The console command name.
18
     *
19
     * @var string
20
     */
21
    protected $name = 'module:migrate:rollback';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Rollback the last database migrations for a specific or all modules';
29
30
    /**
31
     * @var Modules
32
     */
33
    protected $module;
34
35
    /**
36
     * Create a new command instance.
37
     *
38
     * @param Modules $module
39
     */
40
    public function __construct(Modules $module)
41
    {
42
        parent::__construct();
43
44
        $this->module = $module;
45
    }
46
47
    /**
48
     * Execute the console command.
49
     *
50
     * @return mixed
51
     */
52
    public function fire()
53
    {
54
        if (!$this->confirmToProceed()) {
55
            return;
56
        }
57
58
        $slug = $this->argument('slug');
59
60
        if ($slug) {
61
            return $this->rollback($slug);
62
        } else {
63
            foreach ($this->module->all() as $module) {
64
                $this->rollback($module['slug']);
65
            }
66
        }
67
    }
68
69
    /**
70
     * Run the migration rollback for the specified module.
71
     *
72
     * @param string $slug
73
     *
74
     * @return mixed
75
     */
76
    protected function rollback($slug)
77
    {
78
        $this->requireMigrations($slug);
79
80
        $this->call('migrate:rollback', [
81
            '--database' => $this->option('database'),
82
            '--force'    => $this->option('force'),
83
            '--pretend'  => $this->option('pretend'),
84
        ]);
85
    }
86
87
    /**
88
     * Get the console command arguments.
89
     *
90
     * @return array
91
     */
92
    protected function getArguments()
93
    {
94
        return [['slug', InputArgument::OPTIONAL, 'Module slug.']];
95
    }
96
97
    /**
98
     * Get the console command options.
99
     *
100
     * @return array
101
     */
102 View Code Duplication
    protected 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...
103
    {
104
        return [
105
            ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
106
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run while in production.'],
107
            ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
108
        ];
109
    }
110
}
111