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.

ModuleSeedCommand::getArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Caffeinated\Modules\Console\Commands;
4
5
use Caffeinated\Modules\Modules;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class ModuleSeedCommand extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'module:seed';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Seed the database with records for a specific or all modules';
25
26
    /**
27
     * @var Modules
28
     */
29
    protected $module;
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @param Modules $module
35
     */
36
    public function __construct(Modules $module)
37
    {
38
        parent::__construct();
39
40
        $this->module = $module;
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return mixed
47
     */
48 View Code Duplication
    public function fire()
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...
49
    {
50
        $slug = $this->argument('slug');
51
52
        if (isset($slug)) {
53
            if (!$this->module->exists($slug)) {
54
                return $this->error('Module does not exist.');
55
            }
56
57
            if ($this->module->isEnabled($slug)) {
58
                $this->seed($slug);
59
            } elseif ($this->option('force')) {
60
                $this->seed($slug);
61
            }
62
63
            return;
64
        } else {
65
            if ($this->option('force')) {
66
                $modules = $this->module->all();
67
            } else {
68
                $modules = $this->module->enabled();
69
            }
70
71
            foreach ($modules as $module) {
72
                $this->seed($module['slug']);
73
            }
74
        }
75
    }
76
77
    /**
78
     * Seed the specific module.
79
     *
80
     * @param string $module
0 ignored issues
show
Bug introduced by
There is no parameter named $module. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
81
     *
82
     * @return array
83
     */
84
    protected function seed($slug)
85
    {
86
        $module        = $this->module->where('slug', $slug)->first();
87
        $params        = [];
88
        $namespacePath = $this->module->getNamespace();
89
        $rootSeeder    = $module['namespace'].'DatabaseSeeder';
90
        $fullPath      = $namespacePath.'\\'.$module['namespace'].'\Database\Seeds\\'.$rootSeeder;
91
92
        if (class_exists($fullPath)) {
93
            if ($this->option('class')) {
94
                $params['--class'] = $this->option('class');
95
            } else {
96
                $params['--class'] = $fullPath;
97
            }
98
99
            if ($option = $this->option('database')) {
100
                $params['--database'] = $option;
101
            }
102
103
            if ($option = $this->option('force')) {
104
                $params['--force'] = $option;
105
            }
106
107
            $this->call('db:seed', $params);
108
        }
109
    }
110
111
    /**
112
     * Get the console command arguments.
113
     *
114
     * @return array
115
     */
116
    protected function getArguments()
117
    {
118
        return [['slug', InputArgument::OPTIONAL, 'Module slug.']];
119
    }
120
121
    /**
122
     * Get the console command options.
123
     *
124
     * @return array
125
     */
126 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...
127
    {
128
        return [
129
            ['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the module\'s root seeder.'],
130
            ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'],
131
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run while in production.'],
132
        ];
133
    }
134
}
135