Passed
Branch v1.5.1 (4f5540)
by Wanderson
05:07
created

Query::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Win\Repositories\Database\Sql;
4
5
use Win\Repositories\Database\Orm;
6
7
/**
8
 * SELECT, UPDATE, DELETE, etc
9
 */
10
class Query
11
{
12
	/** @var Orm */
13
	protected $orm;
14
15
	/**
16
	 * Responsável por gerar a Query completa
17
	 * @var Builder
18
	 */
19
	protected $builder;
20
21
	/** @var string */
22
	public $table;
23
24
	/** @var string */
25
	public $raw = null;
26
27
	/** @var array */
28
	public $values = [];
29
30
	/** @var Where */
31
	public $where;
32
33
	/** @var OrderBy */
34
	public $orderBy;
35
36
	/** @var Limit */
37
	public $limit;
38
39
	/**
40
	 * Prepara a query
41
	 * @param Orm $orm
42
	 */
43
	public function __construct(Orm $orm)
44
	{
45
		$this->table = $orm::TABLE;
46
		$this->orm = $orm;
47
48
		$this->where = new Where();
49
		$this->orderBy = new OrderBy();
50
		$this->limit = new Limit();
51
	}
52
53
	/**
54
	 * Define o builder da Query
55
	 * @param string $statementType
56
	 * @return $this
57
	 * @example setStatement('SELECT'|'UPDATE'|'DELETE')
58
	 */
59
	public function build($statementType)
60
	{
61
		$this->builder = Builder::factory($statementType, $this);
62
63
		return $this;
64
	}
65
66
	/** @return mixed[] */
67
	public function getValues()
68
	{
69
		return array_values($this->builder->getValues());
70
	}
71
72
	/**
73
	 * Retorna o comando SQL
74
	 * @return string
75
	 */
76
	public function __toString()
77
	{
78
		if ($this->orm->debug) {
79
			print_r('<pre>' . $this->builder . '<br/>');
80
			print_r($this->getValues());
81
			print_r('</pre>');
82
		}
83
84
		return (string) $this->builder;
85
	}
86
}
87