Table   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 2
A getItems() 0 8 2
getItem() 0 1 ?
A addDecorators() 0 12 3
1
<?php namespace Xethron\MigrationsGenerator\Syntax;
2
3
/**
4
 * Class Table
5
 * @package Xethron\MigrationsGenerator\Syntax
6
 */
7
abstract class Table extends \Way\Generators\Syntax\Table{
8
9
	/**
10
	 * @var string
11
	 */
12
	protected $table;
13
14
    /**
15
     * @param array  $fields
16
     * @param string $table
17
     * @param string $method
18
     * @param null   $connection
19
     *
20
     * @return string
21
     */
22
	public function run(array $fields, $table, $connection = null, $method = 'table')
23
	{
24
		$table = substr($table, strlen(\DB::getTablePrefix()));
25
		$this->table = $table;
26
        if (!is_null($connection)) $method = 'connection(\''.$connection.'\')->'.$method;
27
		$compiled = $this->compiler->compile($this->getTemplate(), ['table'=>$table,'method'=>$method]);
28
		return $this->replaceFieldsWith($this->getItems($fields), $compiled);
29
	}
30
31
	/**
32
	 * Return string for adding all foreign keys
33
	 *
34
	 * @param array $items
35
	 * @return array
36
	 */
37
	protected function getItems(array $items)
38
	{
39
		$result = array();
40
		foreach($items as $item) {
41
			$result[] = $this->getItem($item);
42
		}
43
		return $result;
44
	}
45
46
	/**
47
	 * @param array $item
48
	 * @return string
49
	 */
50
	abstract protected function getItem(array $item);
51
52
	/**
53
	 * @param $decorators
54
	 * @return string
55
	 */
56
	protected function addDecorators($decorators)
57
	{
58
		$output = '';
59
		foreach ($decorators as $decorator) {
60
			$output .= sprintf("->%s", $decorator);
61
			// Do we need to tack on the parentheses?
62
			if (strpos($decorator, '(') === false) {
63
				$output .= '()';
64
			}
65
		}
66
		return $output;
67
	}
68
}
69