Completed
Push — master ( ecbf0c...c8753a )
by Ron
02:19
created

WhereBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 2
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A where() 0 3 1
A buildWhereConditions() 0 2 1
1
<?php
2
namespace Kir\MySQL\Builder\Traits;
3
4
use Kir\MySQL\Builder\Expr\OptionalExpression;
5
use Kir\MySQL\Builder\Internal\ConditionBuilder;
6
7
trait WhereBuilder {
8
	use AbstractDB;
9
	use ConditionDefinition;
10
11
	/** @var array[] */
12
	private $where = [];
13
14
	/**
15
	 * @param string|array|OptionalExpression $expression
16
	 * @param array<int, mixed> $args
17
	 * @return $this
18
	 */
19
	public function where($expression, ...$args) {
20
		$fn = function (...$args) { $this->where[] = $args; };
21
		return $this->addCondition($fn, $expression, ...$args);
22
	}
23
24
	/**
25
	 * @param string $query
26
	 * @return string
27
	 */
28
	protected function buildWhereConditions($query) {
29
		return ConditionBuilder::build($this->db(), $query, $this->where, 'WHERE');
30
	}
31
}
32