| Conditions | 6 |
| Paths | 4 |
| Total Lines | 67 |
| Code Lines | 46 |
| 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 |
||
| 45 | public function generate() |
||
| 46 | { |
||
| 47 | $generatedFiles = []; |
||
| 48 | |||
| 49 | if($this::$initializeFlag == 0){ |
||
| 50 | $laragen = app('laragen'); |
||
| 51 | $modules = $laragen->getModules(); |
||
|
|
|||
| 52 | $permissions = []; |
||
| 53 | $editPermissions = []; |
||
| 54 | $viewPermissions = []; |
||
| 55 | foreach ($modules as $module) { |
||
| 56 | $permissions[] = 'create_'.$module->getModuleName(); |
||
| 57 | $permissions[] = 'view_'.$module->getModuleName(); |
||
| 58 | $permissions[] = 'edit_'.$module->getModuleName(); |
||
| 59 | $permissions[] = 'delete_'.$module->getModuleName(); |
||
| 60 | foreach ($module->getColumns() as $field) { |
||
| 61 | $editPermissions[] = 'edit_'.$module->getModuleName().'_'.$field->getColumnKey(); |
||
| 62 | $viewPermissions[] = 'view_'.$module->getModuleName().'_'.$field->getColumnKey(); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | $allPermissions = []; |
||
| 66 | $allPermissions = array_merge($allPermissions, $permissions, $editPermissions, $viewPermissions); |
||
| 67 | |||
| 68 | $permissionsCode = ''; |
||
| 69 | foreach ($allPermissions as $permission) { |
||
| 70 | $permissionsCode .= "Permission::create(['name' => '". $permission ."']);" . PHP_EOL. $this->getTabs(2); |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 74 | $permissionSeederTemplate = $this->buildTemplate('common/permissionSeeder', [ |
||
| 75 | '{{permissions}}' => $permissionsCode, |
||
| 76 | '{{viewPermissions}}' => implode("', '", $viewPermissions), |
||
| 77 | '{{editPermissions}}' => implode("', '", $editPermissions), |
||
| 78 | ]); |
||
| 79 | |||
| 80 | $fullFilePath = $this->getPath("database/factories/")."RolesAndPermissionsSeeder.php"; |
||
| 81 | file_put_contents($fullFilePath, $permissionSeederTemplate); |
||
| 82 | $generatedFiles[] = $fullFilePath; |
||
| 83 | |||
| 84 | } |
||
| 85 | $factoryTemplate = $this->buildTemplate('common/Factories/Factory', [ |
||
| 86 | '{{modelName}}' => $this->module->getModelName(), |
||
| 87 | '{{usedModels}}' => $this->getUsedModels($this->module->getFilteredColumns(['hasSingleRelation', 'hasPivot'])), |
||
| 88 | '{{dataDefinition}}' => $this->getDataDefinition($this->module->getFilteredColumns(['general'])), |
||
| 89 | '{{foreignData}}' => $this->getForeignData($this->module->getFilteredColumns(['hasSingleRelation'])) |
||
| 90 | ]); |
||
| 91 | |||
| 92 | $fullFilePath = $this->getPath("database/factories/").$this->module->getModelName()."Factory.php"; |
||
| 93 | file_put_contents($fullFilePath, $factoryTemplate); |
||
| 94 | $generatedFiles[] = $fullFilePath; |
||
| 95 | |||
| 96 | foreach($this->module->getFilteredColumns(['hasPivot']) as $type){ |
||
| 97 | $typeTemplate = $this->buildTemplate('common/Factories/Factory', [ |
||
| 98 | '{{modelName}}' => $type->getPivot(), |
||
| 99 | '{{usedModels}}' => $this->getUsedModels($type->getFilteredColumns('hasSingleRelation'), $type->getPivot()), |
||
| 100 | '{{dataDefinition}}' => $this->getDataDefinition($type->getFilteredColumns('general')), |
||
| 101 | '{{foreignData}}' => $this->getForeignData($type->getFilteredColumns('hasSingleRelation')) |
||
| 102 | ]); |
||
| 103 | |||
| 104 | $fullFilePath = $this->getPath("database/factories/").Str::singular($type->getPivot())."Factory.php"; |
||
| 105 | file_put_contents($fullFilePath, $typeTemplate); |
||
| 106 | $generatedFiles[] = $fullFilePath; |
||
| 107 | } |
||
| 108 | |||
| 109 | $generatedFiles[] = $this->updateSeeder(); |
||
| 110 | |||
| 111 | return $generatedFiles; |
||
| 112 | } |
||
| 222 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.