1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Nwidart\Modules\Support\Stub; |
7
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
|
10
|
|
|
class MakeFactoryCommand extends GeneratorCommand |
11
|
|
|
{ |
12
|
|
|
use ModuleCommandTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The name of argument name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $argumentName = 'name'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command name. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name = 'module:make-factory'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The console command description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $description = 'Create a new model factory for the specified module.'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the console command arguments. |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
59 |
|
protected function getArguments() |
41
|
|
|
{ |
42
|
|
|
return array( |
43
|
59 |
|
array('name', InputArgument::REQUIRED, 'The name of the factory.'), |
44
|
|
|
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return mixed |
50
|
|
|
*/ |
51
|
2 |
|
protected function getTemplateContents() |
52
|
|
|
{ |
53
|
2 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
|
|
|
54
|
|
|
|
55
|
2 |
|
return (new Stub('/factory.stub'))->render(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
2 |
|
protected function getDestinationFilePath() |
62
|
|
|
{ |
63
|
2 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
64
|
|
|
|
65
|
|
|
// $factoryPath = $this->laravel['modules']->config('paths.generator.factories'); |
|
|
|
|
66
|
|
|
|
67
|
2 |
|
return $path . 'Database/factories/' . $this->getFileName(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
2 |
|
private function getFileName() |
74
|
|
|
{ |
75
|
2 |
|
return Str::studly($this->argument('name')) . '.php'; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.