| Conditions | 6 |
| Paths | 18 |
| Total Lines | 53 |
| Code Lines | 36 |
| 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 |
||
| 12 | public function generate() |
||
| 13 | { |
||
| 14 | $generatedFiles = []; |
||
| 15 | $migrationTemplate = $this->buildTemplate('common/migrations/table', [ |
||
| 16 | '{{modelName}}' => $this->module->getModelName(), |
||
| 17 | '{{modelNamePlural}}' => $this->module->getModelNamePlural(), |
||
| 18 | '{{moduleName}}' => $this->module->getModuleName(), |
||
| 19 | '{{modelTableSchema}}' => $this->getSchema() |
||
| 20 | ]); |
||
| 21 | |||
| 22 | $fullFilePath = $this->getMigrationFile(); |
||
| 23 | file_put_contents($fullFilePath, $migrationTemplate); |
||
| 24 | $generatedFiles[] = $fullFilePath; |
||
| 25 | |||
| 26 | foreach ($this->module->getGalleries() as $gallery) { |
||
| 27 | $pivotTemplate = $this->buildTemplate('common/migrations/pivot', [ |
||
| 28 | '{{pivotName}}' => $this->module->getPivotName($gallery), |
||
| 29 | '{{pivotTableName}}' => $this->module->getPivotTableName($gallery), |
||
| 30 | '{{pivotTableSchema}}' => $this->getGallerySchema($gallery) |
||
| 31 | ]); |
||
| 32 | $pivotFilePath = $this->getPivotFile($gallery); |
||
| 33 | file_put_contents($pivotFilePath, $pivotTemplate); |
||
| 34 | $generatedFiles[] = $pivotFilePath; |
||
| 35 | } |
||
| 36 | |||
| 37 | foreach ($this->module->getForeignColumns('related') as $relatedModules) { |
||
| 38 | foreach ($relatedModules as $related) { |
||
| 39 | $pivotTemplate = $this->buildTemplate('common/migrations/pivot', [ |
||
| 40 | '{{pivotName}}' => $this->module->getPivotName($related), |
||
| 41 | '{{pivotTableName}}' => $this->module->getPivotTableName($related), |
||
| 42 | '{{pivotTableSchema}}' => $this->getPivotSchema($related) |
||
| 43 | ]); |
||
| 44 | } |
||
| 45 | $pivotFilePath = $this->getPivotFile($related); |
||
|
|
|||
| 46 | file_put_contents($pivotFilePath, $pivotTemplate); |
||
| 47 | $generatedFiles[] = $pivotFilePath; |
||
| 48 | } |
||
| 49 | |||
| 50 | foreach ($this->module->getMultipleColumns() as $multipleModules) { |
||
| 51 | foreach ($multipleModules as $multiple => $multipleData) { |
||
| 52 | $pivotTemplate = $this->buildTemplate('common/migrations/pivot', [ |
||
| 53 | '{{pivotName}}' => str_singular($this->module->getPivotName($multiple)), |
||
| 54 | '{{pivotTableName}}' => str_plural($this->module->getPivotTableName($multiple)), |
||
| 55 | '{{pivotTableSchema}}' => $this->getMultipleSchema($multipleData) |
||
| 56 | ]); |
||
| 57 | |||
| 58 | $pivotFilePath = $this->getPivotFile($multiple); |
||
| 59 | file_put_contents($pivotFilePath, $pivotTemplate); |
||
| 60 | $generatedFiles[] = $pivotFilePath; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return $generatedFiles; |
||
| 65 | } |
||
| 152 |