| Conditions | 7 |
| Paths | 48 |
| Total Lines | 65 |
| Code Lines | 49 |
| 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 |
||
| 69 | public function fire() |
||
| 70 | { |
||
| 71 | $this->generators = new Collection(); |
||
| 72 | if($this->argument('domain') && $this->argument('domain-path')) { |
||
| 73 | $domain = $this->argument('domain'); |
||
| 74 | $domainPath = $this->argument('domain-path'); |
||
| 75 | } else { |
||
| 76 | $domain = $this->getDomainNameForRepo(); |
||
| 77 | $domainPath = $this->laravel['domains']->getDomainPath($domain); |
||
| 78 | } |
||
| 79 | |||
| 80 | $migrationGenerator = new MigrationGenerator([ |
||
| 81 | 'name' => 'create_' . Str::snake(Str::plural($this->argument('name'))) . '_table', |
||
|
|
|||
| 82 | 'fields' => $this->option('fillable'), |
||
| 83 | 'force' => $this->option('force'), |
||
| 84 | ],$domain,$domainPath); |
||
| 85 | |||
| 86 | if (!$this->option('skip-migration')) { |
||
| 87 | $this->generators->push($migrationGenerator); |
||
| 88 | } |
||
| 89 | |||
| 90 | $modelGenerator = new ModelGenerator([ |
||
| 91 | 'name' => $this->argument('name'), |
||
| 92 | 'fillable' => $this->option('fillable'), |
||
| 93 | 'force' => $this->option('force') |
||
| 94 | ],$domain,$domainPath); |
||
| 95 | |||
| 96 | $modelRelationsGenerator = new ModelRelationsGenerator([ |
||
| 97 | 'name' => $this->argument('name'), |
||
| 98 | 'force' => $this->option('force'), |
||
| 99 | ],$domain,$domainPath); |
||
| 100 | |||
| 101 | if (!$this->option('skip-model')) { |
||
| 102 | $this->generators->push($modelGenerator); |
||
| 103 | $this->generators->push($modelRelationsGenerator); |
||
| 104 | } |
||
| 105 | |||
| 106 | $this->generators->push(new RepositoryInterfaceGenerator([ |
||
| 107 | 'name' => $this->argument('name'), |
||
| 108 | 'force' => $this->option('force'), |
||
| 109 | ],$domain,$domainPath)); |
||
| 110 | |||
| 111 | foreach ($this->generators as $generator) { |
||
| 112 | $generator->run(); |
||
| 113 | } |
||
| 114 | |||
| 115 | $model = $modelGenerator->getRootNamespace() . '\\' . $modelGenerator->getName(); |
||
| 116 | $model = str_replace([ |
||
| 117 | "\\", |
||
| 118 | '/' |
||
| 119 | ], '\\', $model); |
||
| 120 | |||
| 121 | try { |
||
| 122 | (new RepositoryEloquentGenerator([ |
||
| 123 | 'name' => $this->argument('name'), |
||
| 124 | 'rules' => $this->option('rules'), |
||
| 125 | 'validator' => $this->option('validator'), |
||
| 126 | 'force' => $this->option('force'), |
||
| 127 | 'model' => $model |
||
| 128 | ],$domain,$domainPath))->run(); |
||
| 129 | $this->info("Repository created successfully."); |
||
| 130 | } catch (FileAlreadyExistsException $e) { |
||
| 131 | $this->error($this->type . ' already exists!'); |
||
| 132 | |||
| 133 | return false; |
||
| 134 | } |
||
| 211 |