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.
Completed
Push — master ( 30fdb1...69a06f )
by Shea
02:33
created

ModuleSeedCommand::seed()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 26
rs 8.439
cc 5
eloc 16
nc 9
nop 1
1
<?php
2
namespace Caffeinated\Modules\Console\Commands;
3
4
use Caffeinated\Modules\Modules;
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class ModuleSeedCommand extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
	protected $name = 'module:seed';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
	protected $description = 'Seed the database with records for a specific or all modules';
24
25
	/**
26
	 * @var Modules
27
	 */
28
	protected $module;
29
30
	/**
31
	 * Create a new command instance.
32
	 *
33
	 * @param Modules  $module
34
	 */
35
	public function __construct(Modules $module)
36
	{
37
		parent::__construct();
38
39
		$this->module = $module;
40
	}
41
42
	/**
43
	 * Execute the console command.
44
	 *
45
	 * @return mixed
46
	 */
47
	public function fire()
48
	{
49
		$slug = $this->argument('slug');
50
51
		if (isset($slug)) {
52
			if (! $this->module->exists($slug)) {
53
				return $this->error("Module does not exist.");
54
			}
55
56
			if ($this->module->isEnabled($slug)) {
57
				$this->seed($slug);
58
			} elseif ($this->option('force')) {
59
				$this->seed($slug);
60
			}
61
62
			return;
63 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
64
			if ($this->option('force')) {
65
				$modules = $this->module->all();
66
			} else {
67
				$modules = $this->module->enabled();
68
			}
69
70
			foreach ($modules as $module) {
71
				$this->seed($module['slug']);
72
			}
73
		}
74
	}
75
76
	/**
77
	 * Seed the specific module.
78
	 *
79
	 * @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...
80
	 * @return array
81
	 */
82
	protected function seed($slug)
83
	{
84
        $module         = $this->module->getProperties($slug);
85
		$params         = [];
86
		$namespacePath  = $this->module->getNamespace();
87
		$rootSeeder     = $module['namespace'].'DatabaseSeeder';
88
		$fullPath       = $namespacePath.'\\'.$module['namespace'].'\Database\Seeds\\'.$rootSeeder;
89
90
		if (class_exists($fullPath)) {
91
			if ($this->option('class')) {
92
				$params['--class'] = $this->option('class');
93
			} else {
94
				$params['--class'] = $fullPath;
95
			}
96
97
			if ($option = $this->option('database')) {
98
				$params['--database'] = $option;
99
			}
100
101
	        if ($option = $this->option('force')) {
102
	            $params['--force'] = $option;
103
	        }
104
105
			$this->call('db:seed', $params);
106
		}
107
	}
108
109
	/**
110
	 * Get the console command arguments.
111
	 *
112
	 * @return array
113
	 */
114
	protected function getArguments()
115
	{
116
		return [['slug', InputArgument::OPTIONAL, 'Module slug.']];
117
	}
118
119
	/**
120
	 * Get the console command options.
121
	 *
122
	 * @return array
123
	 */
124 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...
125
	{
126
		return [
127
			['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the module\'s root seeder.'],
128
			['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'],
129
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run while in production.'],
130
		];
131
	}
132
}
133