Passed
Branch master (23c1c2)
by Wanderson
03:02
created

OrderBy::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Win\Repositories\Database\Sql;
4
5
/**
6
 * ORDER BY ___ DESC
7
 */
8
class OrderBy
9
{
10
	/**
11
	 * Regras de ordenação
12
	 * @var string[]
13
	 */
14
	private $rules;
15
16
	/**
17
	 * Prepara a cláusula SQL
18
	 */
19
	public function __construct()
20
	{
21
		$this->rules = [];
22
	}
23
24
	/**
25
	 * Retorna o SQL da cláusula
26
	 * @return string
27
	 */
28
	public function __toString()
29
	{
30
		if (!empty($this->rules)) {
31
			ksort($this->rules);
32
33
			return ' ORDER BY ' . implode(', ', $this->rules);
34
		}
35
36
		return '';
37
	}
38
39
	/**
40
	 * Define a ordenação principal
41
	 * @param string $orderBy
42
	 */
43
	public function set($orderBy)
44
	{
45
		$this->rules = [$orderBy];
46
	}
47
48
	/**
49
	 * Adiciona uma ordenação
50
	 * @param string $orderBy
51
	 * @param int $priority
52
	 */
53
	public function add($orderBy, $priority = 0)
54
	{
55
		$this->rules[$priority] = $orderBy;
56
	}
57
58
	/**
59
	 * Remove as ordenações
60
	 */
61
	public function reset()
62
	{
63
		$this->rules = [];
64
	}
65
}
66