|
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
|
1 |
|
protected function getTemplateContents() |
|
52
|
|
|
{ |
|
53
|
1 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
1 |
|
return (new Stub('/factory.stub'))->render(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
*/ |
|
61
|
1 |
|
protected function getDestinationFilePath() |
|
62
|
|
|
{ |
|
63
|
1 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
64
|
|
|
|
|
65
|
|
|
// $factoryPath = $this->laravel['modules']->config('paths.generator.factories'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
1 |
|
return $path . 'Database/factories/' . $this->getFileName(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
1 |
|
private function getFileName() |
|
74
|
|
|
{ |
|
75
|
1 |
|
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
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.