ControllerCommand::handle()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 4
nc 6
nop 0
1
<?php namespace Wn\Generators\Commands;
2
3
4
use InvalidArgumentException;
5
6
class ControllerCommand extends BaseCommand {
7
8
	protected $signature = 'wn:controller
9
        {model : Name of the model (with namespace if not App)}
10
		{--no-routes= : without routes}
11
        {--force= : override the existing files}
12
        {--laravel : Use Laravel style route definitions}
13
    ';
14
15
	protected $description = 'Generates RESTful controller using the RESTActions trait';
16
17
    public function handle()
18
    {
19
    	$model = $this->argument('model');
20
    	$name = '';
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
    	if(strrpos($model, "\\") === false){
22
    		$name = $model;
23
    		$model = "App\\Models\\" . $model;
24
    	} else {
25
    		$name = explode("\\", $model);
26
    		$name = $name[count($name) - 1];
27
    	}
28
        $controller = ucwords(\Illuminate\Support\Str::plural($name)) . 'Controller';
29
        $content = $this->getTemplate('controller')
30
        	->with([
31
        		'name' => $controller,
32
        		'model' => $model
33
        	])
34
        	->get();
35
36
        $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
37
        if(! $this->option('no-routes')){
38
            $options = [
39
                'resource' => \Illuminate\Support\Str::snake($name, '-'),
40
                '--controller' => $controller,
41
            ];
42
43
            if ($this->option('laravel')) {
44
                $options['--laravel'] = true;
45
            }
46
47
            $this->call('wn:route', $options);
48
        }
49
    }
50
51
}
52