AddToTable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getItem() 0 35 5
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