TableBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
dl 0
loc 36
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildTables() 0 9 3
A getTables() 0 2 1
A addTable() 0 3 1
1
<?php
2
namespace Kir\MySQL\Builder\Traits;
3
4
use Kir\MySQL\Builder\Internal\Types;
5
6
/**
7
 * @phpstan-import-type DBTableNameType from Types
8
 */
9
trait TableBuilder {
10
	use AbstractTableNameBuilder;
11
12
	/** @var array<int, array{alias: string|null, name: DBTableNameType}> */
13
	private $tables = [];
14
15
	/**
16
	 * @param string|null $alias
17
	 * @param DBTableNameType $table
0 ignored issues
show
Bug introduced by
The type Kir\MySQL\Builder\Traits\DBTableNameType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
	 * @return $this
19
	 */
20
	protected function addTable(?string $alias, $table) {
21
		$this->tables[] = ['alias' => $alias, 'name' => $table];
22
		return $this;
23
	}
24
25
	/**
26
	 * @param string $query
27
	 * @return string
28
	 */
29
	protected function buildTables(string $query): string {
30
		$arr = [];
31
		foreach($this->tables as $table) {
32
			$arr[] = "\t".$this->buildTableName($table['alias'], $table['name']);
33
		}
34
		if(count($arr)) {
35
			$query .= implode(",\n", $arr)."\n";
36
		}
37
		return $query;
38
	}
39
40
	/**
41
	 * @return array<int, array{alias: string|null, name: DBTableNameType}>
42
	 */
43
	protected function getTables(): array {
44
		return $this->tables;
45
	}
46
}
47