| Conditions | 5 |
| Paths | 16 |
| Total Lines | 65 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 14 | public function generate() |
||
| 15 | { |
||
| 16 | $generatedFiles = []; |
||
| 17 | |||
| 18 | $backendAuthRouteFile = $this->getPath(self::$destination."/backend//")."auth.php"; |
||
| 19 | $webRouteFile = $this->getPath(self::$destination."/frontend//")."web.php"; |
||
| 20 | $backendApiRouteFile = $this->getPath(self::$destination."/backend//")."api.php"; |
||
| 21 | $backendWebRouteFile = $this->getPath(self::$destination."/backend//")."web.php"; |
||
| 22 | |||
| 23 | if (self::$initializeFlag++ == 0) { |
||
| 24 | $this->initializeFiles([ |
||
| 25 | $backendAuthRouteFile => "backend/routes/auth", |
||
| 26 | $backendApiRouteFile => "backend/routes/api", |
||
| 27 | $backendWebRouteFile => "backend/routes/web" |
||
| 28 | ]); |
||
| 29 | } |
||
| 30 | |||
| 31 | $laragen = LaragenOptions::getInstance(); |
||
| 32 | if ($laragen->generatorExists('Frontend\\Controller')) { |
||
| 33 | $this->insertIntoFile( |
||
| 34 | $webRouteFile, |
||
| 35 | "<?php\n", |
||
| 36 | "use App\\Http\\Controllers\\".$this->module->getModelName()."Controller;\n" |
||
| 37 | ); |
||
| 38 | |||
| 39 | $this->insertIntoFile( |
||
| 40 | $webRouteFile, |
||
| 41 | "/"."* Insert your routes here */", |
||
| 42 | "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
||
| 43 | ); |
||
| 44 | $generatedFiles[] = $webRouteFile; |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($laragen->generatorExists('Backend\\Controller')) { |
||
| 48 | $this->insertIntoFile( |
||
| 49 | $backendWebRouteFile, |
||
| 50 | "<?php\n", |
||
| 51 | "use App\\Http\\Controllers\\Backend\\".$this->module->getModelName()."Controller;\n" |
||
| 52 | ); |
||
| 53 | |||
| 54 | $this->insertIntoFile( |
||
| 55 | $backendWebRouteFile, |
||
| 56 | "/"."* Insert your routes here */", |
||
| 57 | "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
||
| 58 | ); |
||
| 59 | $generatedFiles[] = $backendWebRouteFile; |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($laragen->generatorExists('Backend\\Api')) { |
||
| 63 | $this->insertIntoFile( |
||
| 64 | $backendApiRouteFile, |
||
| 65 | "<?php\n", |
||
| 66 | "use App\\Http\\Controllers\\Backend\\Api\\".$this->module->getModelName()."Controller;\n" |
||
| 67 | ); |
||
| 68 | |||
| 69 | $this->insertIntoFile( |
||
| 70 | $backendApiRouteFile, |
||
| 71 | "/"."* Insert your routes here */", |
||
| 72 | "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
||
| 73 | ); |
||
| 74 | |||
| 75 | $generatedFiles[] = $backendApiRouteFile; |
||
| 76 | } |
||
| 77 | |||
| 78 | return $generatedFiles; |
||
| 79 | } |
||
| 81 |