AddToTable::getItem()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.439
c 0
b 0
f 0
cc 5
eloc 20
nc 12
nop 1
1
<?php namespace Xethron\MigrationsGenerator\Syntax;
2
3
/**
4
 * Class AddToTable
5
 * @package Xethron\MigrationsGenerator\Syntax
6
 */
7
class AddToTable extends Table {
8
9
	/**
10
	 * Return string for adding a column
11
	 *
12
	 * @param array $field
13
	 * @return string
14
	 */
15
	protected function getItem(array $field)
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 (isset($field['args'])) {
38
			$output = sprintf(
39
				"\$table->%s(%s, %s)",
40
				$type,
41
				$property,
42
				$field['args']
43
			);
44
		}
45
		if (isset($field['decorators'])) {
46
			$output .= $this->addDecorators( $field['decorators'] );
47
		}
48
		return $output . ';';
49
	}
50
}
51