| Conditions | 10 |
| Paths | 32 |
| Total Lines | 50 |
| 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 |
||
| 118 | public function getStub() |
||
| 119 | { |
||
| 120 | $parser = $this->getNameParser(); |
||
| 121 | |||
| 122 | $action = $parser->getAction(); |
||
| 123 | switch ($action) { |
||
| 124 | case 'add': |
||
| 125 | case 'append': |
||
| 126 | case 'update': |
||
| 127 | case 'insert': |
||
| 128 | $file = 'change'; |
||
| 129 | $replacements = [ |
||
| 130 | 'class' => $this->getClass(), |
||
| 131 | 'table' => $parser->getTable(), |
||
| 132 | 'fields_up' => $this->getSchemaParser()->up(), |
||
| 133 | 'fields_down' => $this->getSchemaParser()->down(), |
||
| 134 | ]; |
||
| 135 | break; |
||
| 136 | |||
| 137 | case 'delete': |
||
| 138 | case 'remove': |
||
| 139 | case 'alter': |
||
| 140 | $file = 'change'; |
||
| 141 | $replacements = [ |
||
| 142 | 'class' => $this->getClass(), |
||
| 143 | 'table' => $parser->getTable(), |
||
| 144 | 'fields_down' => $this->getSchemaParser()->up(), |
||
| 145 | 'fields_up' => $this->getSchemaParser()->down(), |
||
| 146 | ]; |
||
| 147 | break; |
||
| 148 | default: |
||
| 149 | $file = 'create'; |
||
| 150 | $replacements = [ |
||
| 151 | 'class' => $this->getClass(), |
||
| 152 | 'table' => $parser->getTable(), |
||
| 153 | 'fields' => $this->getSchemaParser()->up(), |
||
| 154 | ]; |
||
| 155 | break; |
||
| 156 | } |
||
| 157 | $path = config('domains.paths.repo-generator.stubsOverridePath', __DIR__); |
||
| 158 | |||
| 159 | if (!file_exists($path . "/Stubs/migration/{$file}.stub")) { |
||
| 160 | $path = __DIR__; |
||
| 161 | } |
||
| 162 | |||
| 163 | if (!file_exists($path . "/Stubs/migration/{$file}.stub")) { |
||
| 164 | throw new FileNotFoundException($path . "/Stubs/migration/{$file}.stub"); |
||
| 165 | } |
||
| 166 | |||
| 167 | return Stub::create($path . "/Stubs/migration/{$file}.stub", $replacements); |
||
| 168 | } |
||
| 170 |