AddForeignKeysToTable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getItem() 0 23 5
1
<?php namespace Xethron\MigrationsGenerator\Syntax;
2
3
/**
4
 * Class AddForeignKeysToTable
5
 * @package Xethron\MigrationsGenerator\Syntax
6
 */
7
class AddForeignKeysToTable extends Table {
8
9
	/**
10
	 * Return string for adding a foreign key
11
	 *
12
	 * @param array $foreignKey
13
	 * @return string
14
	 */
15
	protected function getItem(array $foreignKey)
16
	{
17
		$value = $foreignKey['field'];
18
		if ( ! empty($foreignKey['name'])) {
19
			$value .= "', '". $foreignKey['name'];
20
		}
21
		$output = sprintf(
22
			"\$table->foreign('%s')->references('%s')->on('%s')",
23
			$value,
24
			$foreignKey['references'],
25
			$foreignKey['on']
26
		);
27
		if ($foreignKey['onUpdate']) {
28
			$output .= sprintf("->onUpdate('%s')", $foreignKey['onUpdate']);
29
		}
30
		if ($foreignKey['onDelete']) {
31
			$output .= sprintf("->onDelete('%s')", $foreignKey['onDelete']);
32
		}
33
		if (isset($foreignKey['decorators'])) {
34
			$output .= $this->addDecorators($foreignKey['decorators']);
35
		}
36
		return $output . ';';
37
	}
38
39
}
40