Completed
Push — master ( aef970...c04073 )
by Ron
02:26
created

TableBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addTable() 0 7 2
A buildTables() 0 10 3
A getTables() 0 3 1
1
<?php
2
namespace Kir\MySQL\Builder\Traits;
3
4
trait TableBuilder {
5
	use AbstractTableNameBuilder;
6
7
	/**
8
	 * @var array[]
9
	 */
10
	private $tables = array();
11
12
	/**
13
	 * @param string $alias
14
	 * @param string $table
15
	 * @return $this
16
	 */
17
	protected function addTable($alias, $table = null) {
18
		if($table === null) {
19
			list($alias, $table) = [$table, $alias];
20
		}
21
		$this->tables[] = array('alias' => $alias, 'name' => $table);
22
		return $this;
23
	}
24
25
	/**
26
	 * @param string $query
27
	 * @return string
28
	 */
29
	protected function buildTables($query) {
30
		$arr = array();
31
		foreach($this->tables as $table) {
32
			$arr[] = "\t".$this->buildTableName($table['alias'], $table['name']);
33
		}
34
		if(count($arr)) {
35
			$query .= join(",\n", $arr)."\n";
36
		}
37
		return $query;
38
	}
39
40
	/**
41
	 * @return string[]
42
	 */
43
	protected function getTables() {
44
		return $this->tables;
45
	}
46
}
47