Conditions | 11 |
Paths | 11 |
Total Lines | 62 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
116 | protected function generate($path, $folder, $type) |
||
117 | { |
||
118 | $content = $this->getStub($type); |
||
119 | |||
120 | if($content === false) |
||
121 | { |
||
122 | echo 'file '.$type.".stub is not exist !"; |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | $template = str_replace( |
||
127 | [ |
||
128 | '{{modelName}}', |
||
129 | "{{folder}}", |
||
130 | "{{path}}", |
||
131 | "{{modelBaseFolderName}}", |
||
132 | "{{interfaceBaseFolderName}}", |
||
133 | ], |
||
134 | [ |
||
135 | $this->repoName, |
||
136 | str_plural($folder), |
||
137 | $path, |
||
138 | str_plural(\Config::get('repository.model','Entity')), |
||
139 | str_plural(\Config::get('repository.interface','Interface')), |
||
140 | ], |
||
141 | $this->getStub($type) |
||
142 | ); |
||
143 | |||
144 | $folder = str_replace('\\','/',$folder); |
||
145 | $path = str_replace('\\','/',$path); |
||
146 | |||
147 | switch ($type) |
||
148 | { |
||
149 | case 'Entity': |
||
150 | $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}"); |
||
151 | $filePath = rtrim($filePath,'/'); |
||
152 | $filePath .= "/"; |
||
153 | file_put_contents($filePath . "{$this->repoName}.php", $template); |
||
154 | break; |
||
155 | case 'Controller': |
||
156 | case 'Request': |
||
157 | case 'Repository': |
||
158 | case 'Interface': |
||
159 | $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}"); |
||
160 | $filePath = rtrim($filePath,'/'); |
||
161 | $filePath .= "/"; |
||
162 | file_put_contents($filePath . "{$this->repoName}{$type}.php", $template); |
||
163 | break; |
||
164 | case 'create': |
||
165 | case 'edit': |
||
166 | case 'index': |
||
167 | case 'show': |
||
168 | $filePath = $this->getFolderOrCreate($folder."/".str_plural($path))."/"; |
||
169 | $repoName = lcfirst($type); |
||
170 | file_put_contents($filePath . $repoName.".blade.php", $template); |
||
171 | break; |
||
172 | default: |
||
173 | $filePath = $this->getFolderOrCreate($folder)."/"; |
||
174 | $repoName = lcfirst($this->repoName); |
||
175 | file_put_contents($filePath . $repoName.".php", $template); |
||
176 | } |
||
177 | return true; |
||
178 | } |
||
193 |