| Conditions | 6 |
| Paths | 18 |
| Total Lines | 42 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Xethron\MigrationsGenerator\Syntax; |
||
| 15 | protected function getItem(array $field): string |
||
| 16 | { |
||
| 17 | $property = $field['field']; |
||
| 18 | |||
| 19 | // If the field is an array, |
||
| 20 | // make it an array in the Migration |
||
| 21 | if (is_array($property)) { |
||
| 22 | $property = "['".implode("', '", $property)."']"; |
||
| 23 | } else { |
||
| 24 | $property = $property ? "'$property'" : null; |
||
| 25 | } |
||
| 26 | |||
| 27 | $type = $field['type']; |
||
| 28 | |||
| 29 | $output = sprintf( |
||
| 30 | "\$table->%s(%s)", |
||
| 31 | $type, |
||
| 32 | $property |
||
| 33 | ); |
||
| 34 | |||
| 35 | // If we have args, then it needs |
||
| 36 | // to be formatted a bit differently |
||
| 37 | if (!empty($field['args'])) { |
||
| 38 | if ($property !== null) { |
||
| 39 | $output = sprintf( |
||
| 40 | "\$table->%s(%s, %s)", |
||
| 41 | $type, |
||
| 42 | $property, |
||
| 43 | implode(', ', $field['args']) |
||
| 44 | ); |
||
| 45 | } else { |
||
| 46 | $output = sprintf( |
||
| 47 | "\$table->%s(%s)", |
||
| 48 | $type, |
||
| 49 | implode(', ', $field['args']) |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | if (isset($field['decorators'])) { |
||
| 54 | $output .= $this->addDecorators($field['decorators']); |
||
| 55 | } |
||
| 56 | return $output.';'; |
||
| 57 | } |
||
| 59 |