Conditions | 2 |
Paths | 2 |
Total Lines | 58 |
Code Lines | 37 |
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 |
||
51 | protected function buildClass($name) |
||
52 | { |
||
53 | if ($this->alreadyExists($name)) { |
||
54 | $this->components->error("This model already exists"); |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | $ary = explode("\\", $name); |
||
59 | $model = $ary[count($ary) - 1]; |
||
60 | $modelVariable = lcfirst($model); |
||
61 | $modelUnderScore = Str::snake($modelVariable); |
||
62 | |||
63 | $this->callSilently("make:migration", ['name' => "create_{$modelUnderScore}s_table"]); |
||
64 | $this->components->info("Migration scaffolding for {$model} model generated successfully."); |
||
65 | |||
66 | $this->callSilently("magic:contract", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
67 | $this->components->info("Magic contract scaffolding for {$model} model generated successfully."); |
||
68 | |||
69 | $this->callSilently("magic:repository", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
70 | $this->components->info("Magic repository scaffolding for {$model} model generated successfully."); |
||
71 | |||
72 | $this->callSilently("magic:service", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
73 | $this->components->info("Magic service scaffolding for {$model} model generated successfully."); |
||
74 | |||
75 | $this->callSilently("magic:controller", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
76 | $this->components->info("Magic controller scaffolding for {$model} model generated successfully."); |
||
77 | |||
78 | $this->callSilently("magic:createRequest", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
79 | $this->components->info("Magic create request scaffolding for {$model} model generated successfully."); |
||
80 | |||
81 | $this->callSilently("magic:updateRequest", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
82 | $this->components->info("Magic update request scaffolding for {$model} model generated successfully."); |
||
83 | |||
84 | $this->callSilently("magic:deleteRequest", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
85 | $this->components->info("Magic delete request scaffolding for {$model} model generated successfully."); |
||
86 | |||
87 | $this->callSilently("magic:readRequest", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
88 | $this->components->info("Magic read request scaffolding for {$model} model generated successfully."); |
||
89 | |||
90 | $this->callSilently("magic:api", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
91 | $this->components->info("Magic api route scaffolding for {$model} model generated successfully."); |
||
92 | |||
93 | $this->callSilently("magic:test", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
94 | $this->components->info("Magic test scaffolding for {$model} model generated successfully."); |
||
95 | |||
96 | $this->callSilently("magic:factory", ['name' => "{$model}", '--variable' => $modelVariable, '--underscore' => $modelUnderScore]); |
||
97 | $this->components->info("Magic factory scaffolding for {$model} model generated successfully."); |
||
98 | |||
99 | $stub = str_replace( |
||
100 | ['DummyModel', '{{ model }}'], class_basename($model), parent::buildClass($name) |
||
101 | ); |
||
102 | |||
103 | $stub = str_replace( |
||
104 | ['DummyModelVariable', '{{ modelVariable }}'], trim($modelVariable, '\\'), $stub |
||
105 | ); |
||
106 | |||
107 | return str_replace( |
||
108 | ['DummyModelUnderScore', '{{ modelUnderScore }}'], trim($modelUnderScore, '\\'), $stub |
||
109 | ); |
||
170 |