| Conditions | 11 |
| Paths | 112 |
| Total Lines | 44 |
| Code Lines | 26 |
| 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 |
||
| 28 | protected function buildDefinition() |
||
| 29 | { |
||
| 30 | $definition = ''; |
||
| 31 | |||
| 32 | foreach ($this->model->columns() as $column) { |
||
| 33 | $dataType = $column->dataType(); |
||
| 34 | if ($column->name() === 'id') { |
||
| 35 | $dataType = 'increments'; |
||
| 36 | } elseif ($column->dataType() === 'id') { |
||
| 37 | $dataType = 'unsignedBigInteger'; |
||
| 38 | } |
||
| 39 | |||
| 40 | $definition .= self::INDENT.'$table->'.$dataType."('{$column->name()}'"; |
||
| 41 | |||
| 42 | if (! empty($column->attributes()) && $column->dataType() !== 'id') { |
||
| 43 | $definition .= ', '; |
||
| 44 | if (in_array($column->dataType(), ['set', 'enum'])) { |
||
| 45 | $definition .= json_encode($column->attributes()); |
||
| 46 | } else { |
||
| 47 | $definition .= implode(', ', $column->attributes()); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | $definition .= ')'; |
||
| 51 | |||
| 52 | foreach ($column->modifiers() as $modifier) { |
||
| 53 | if (is_array($modifier)) { |
||
| 54 | $definition .= '->'.key($modifier).'('.current($modifier).')'; |
||
| 55 | } else { |
||
| 56 | $definition .= '->'.$modifier.'()'; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $definition .= ';'.PHP_EOL; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($this->model->usesSoftDeletes()) { |
||
| 64 | $definition .= self::INDENT.'$table->'.$this->model->softDeletesDataType().'();'.PHP_EOL; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($this->model->usesTimestamps()) { |
||
| 68 | $definition .= self::INDENT.'$table->'.$this->model->timestampsDataType().'();'.PHP_EOL; |
||
| 69 | } |
||
| 70 | |||
| 71 | return trim($definition); |
||
| 72 | } |
||
| 86 |