1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JunaidQadirB\Cray\Console\Commands; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use JunaidQadirB\Cray\Console\Contracts\GeneratorCommand; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
|
10
|
|
|
class RequestMakeCommand extends GeneratorCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'cray:request'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Create a new form request class'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The type of class being generated. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $type = 'Request'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the stub file for the generator. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
protected function getStub() |
39
|
|
|
{ |
40
|
|
|
if (!$this->option('type') || $this->option('type') == 'store') { |
41
|
|
|
return config('cray.stubs_dir') . '/request.stub'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return config('cray.stubs_dir') . '/request.update.stub'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function buildClass($name) |
48
|
|
|
{ |
49
|
|
|
$replace = []; |
50
|
|
|
if ($model = $this->option('model')) { |
|
|
|
|
51
|
|
|
$model = Str::studly(class_basename($this->option('model'))); |
52
|
|
|
$slug = Str::slug(str_to_words($model), '_'); |
53
|
|
|
$replace['$modelSlug$'] = $slug; |
54
|
|
|
$replace['$modelTable$'] = Str::plural($slug, 2); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return str_replace( |
58
|
|
|
array_keys($replace), array_values($replace), parent::buildClass($name) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the default namespace for the class. |
64
|
|
|
* |
65
|
|
|
* @param string $rootNamespace |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function getDefaultNamespace($rootNamespace) |
70
|
|
|
{ |
71
|
|
|
return $rootNamespace . '\Http\Requests'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the console command options. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
protected function getOptions() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
['model', 'm', InputOption::VALUE_REQUIRED, 'The given model.'], |
83
|
|
|
['type', 't', InputOption::VALUE_OPTIONAL, 'Type of request. Values can be store or update'], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.