| Conditions | 9 |
| Paths | 21 |
| Total Lines | 51 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 57 | public function generate() |
||
| 58 | { |
||
| 59 | if (true === $this->commandData->getAddOn('datatables')) { |
||
| 60 | if (true === $this->commandData->getOption('repositoryPattern')) { |
||
| 61 | $templateName = 'datatable_controller'; |
||
| 62 | } else { |
||
| 63 | $templateName = 'model_datatable_controller'; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (true === $this->commandData->isLocalizedTemplates()) { |
||
| 67 | $templateName .= '_locale'; |
||
| 68 | } |
||
| 69 | |||
| 70 | $templateData = get_template("scaffold.controller.$templateName", 'laravel-generator'); |
||
| 71 | |||
| 72 | parent::generateDataTable(); |
||
| 73 | } elseif (true === $this->commandData->jqueryDT()) { |
||
| 74 | $templateName = 'jquery_datatable_controller'; |
||
| 75 | $templateData = get_template("scaffold.controller.$templateName", 'laravel-generator'); |
||
| 76 | |||
| 77 | parent::generateDataTable(); |
||
| 78 | } else { |
||
| 79 | if (true === $this->commandData->getOption('repositoryPattern')) { |
||
| 80 | $templateName = 'controller'; |
||
| 81 | } else { |
||
| 82 | $templateName = 'model_controller'; |
||
| 83 | } |
||
| 84 | if (true === $this->commandData->isLocalizedTemplates()) { |
||
| 85 | $templateName .= '_locale'; |
||
| 86 | } |
||
| 87 | if (true === $this->commandData->getOption('vue')) { |
||
| 88 | $templateName .= '_inertia'; |
||
| 89 | } |
||
| 90 | |||
| 91 | $templateData = get_template("scaffold.controller.$templateName", 'laravel-generator'); |
||
| 92 | |||
| 93 | $paginate = $this->commandData->getOption('paginate'); |
||
| 94 | |||
| 95 | if (true === $paginate) { |
||
| 96 | $templateData = str_replace('$RENDER_TYPE$', 'paginate('.$paginate.')', $templateData); |
||
| 97 | } else { |
||
| 98 | $templateData = str_replace('$RENDER_TYPE$', 'all()', $templateData); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | $templateData = fill_template($this->commandData->dynamicVars, $templateData); |
||
| 103 | |||
| 104 | FileUtil::createFile($this->path, $this->fileName, $templateData); |
||
| 105 | |||
| 106 | $this->commandData->commandComment("\nController created: "); |
||
| 107 | $this->commandData->commandInfo($this->fileName); |
||
| 108 | } |
||
| 110 |