1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Caffeinated\Modules\Console\Generators; |
4
|
|
|
|
5
|
|
View Code Duplication |
class MakeModelCommand extends MakeCommand |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* The name and signature of the console command. |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $signature = 'make:module:model |
13
|
|
|
{slug : The slug of the module.} |
14
|
|
|
{name : The name of the model class.}'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command description. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $description = 'Create a new module model class'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* String to store the command type. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $type = 'Model'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Module folders to be created. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $listFolders = [ |
36
|
|
|
'Models/', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Module files to be created. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $listFiles = [ |
45
|
|
|
'{{filename}}.php', |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Module stubs used to populate defined files. |
50
|
|
|
* |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
protected $listStubs = [ |
54
|
|
|
'default' => [ |
55
|
|
|
'model.stub', |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Resolve Container after getting file path. |
61
|
|
|
* |
62
|
|
|
* @param string $filePath |
63
|
|
|
* |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
protected function resolveByPath($filePath) |
67
|
|
|
{ |
68
|
|
|
$this->container['filename'] = $this->makeFileName($filePath); |
69
|
|
|
$this->container['namespace'] = $this->getNamespace($filePath); |
70
|
|
|
$this->container['path'] = $this->getBaseNamespace(); |
71
|
|
|
$this->container['classname'] = basename($filePath); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Replace placeholder text with correct values. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function formatContent($content) |
80
|
|
|
{ |
81
|
|
|
return str_replace( |
82
|
|
|
[ |
83
|
|
|
'{{filename}}', |
84
|
|
|
'{{path}}', |
85
|
|
|
'{{namespace}}', |
86
|
|
|
'{{classname}}', |
87
|
|
|
], |
88
|
|
|
[ |
89
|
|
|
$this->container['filename'], |
90
|
|
|
$this->container['path'], |
91
|
|
|
$this->container['namespace'], |
92
|
|
|
$this->container['classname'], |
93
|
|
|
], |
94
|
|
|
$content |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.