Conditions | 6 |
Paths | 32 |
Total Lines | 31 |
Code Lines | 20 |
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 $foreignKey): string |
||
16 | { |
||
17 | // Check for multiple columns |
||
18 | if (count($foreignKey['field']) > 1) { |
||
19 | $value = "['" . implode("', '", $foreignKey['field']) . "']"; |
||
20 | $references = "['" . implode("', '", $foreignKey['references']) . "']"; |
||
21 | } else { |
||
22 | $value = "'" . $foreignKey['field'][0] . "'"; |
||
23 | $references = "'" . $foreignKey['references'][0] . "'"; |
||
24 | } |
||
25 | |||
26 | if (!empty($foreignKey['name'])) { |
||
27 | $value .= ", '" . $foreignKey['name'] . "'"; |
||
28 | } |
||
29 | |||
30 | $output = sprintf( |
||
31 | "\$table->foreign(%s)->references(%s)->on('%s')", |
||
32 | $value, |
||
33 | $references, |
||
34 | $foreignKey['on'] |
||
35 | ); |
||
36 | if ($foreignKey['onUpdate']) { |
||
37 | $output .= sprintf("->onUpdate('%s')", $foreignKey['onUpdate']); |
||
38 | } |
||
39 | if ($foreignKey['onDelete']) { |
||
40 | $output .= sprintf("->onDelete('%s')", $foreignKey['onDelete']); |
||
41 | } |
||
42 | if (isset($foreignKey['decorators'])) { |
||
43 | $output .= $this->addDecorators($foreignKey['decorators']); |
||
44 | } |
||
45 | return $output.';'; |
||
46 | } |
||
48 |