Distinct::distinctRow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Adrian Dumitru
5
 * Date: 7/28/2017
6
 * Time: 8:04 AM
7
 */
8
9
namespace Qpdb\QueryBuilder\Traits;
10
11
12
use Qpdb\QueryBuilder\Dependencies\QueryException;
13
use Qpdb\QueryBuilder\Dependencies\QueryStructure;
14
15
/**
16
 * Trait Distinct
17
 * @package Qpdb\QueryBuilder\Traits
18
 * @property  QueryStructure $queryStructure
19
 */
20
trait Distinct
21
{
22
23
	/**
24
	 * @return $this
25
	 * @throws QueryException
26
	 */
27
	public function all()
28
	{
29
		$this->queryStructure->setElement( QueryStructure::DISTINCT, 0 );
30
31
		return $this;
32
	}
33
34
	/**
35
	 * @return $this
36
	 */
37
	public function distinct()
38
	{
39
		$this->queryStructure->setElement( QueryStructure::DISTINCT, 1 );
40
41
		return $this;
42
	}
43
44
	/**
45
	 * @return $this
46
	 */
47
	public function distinctRow()
48
	{
49
		$this->queryStructure->setElement( QueryStructure::DISTINCT, 2 );
50
51
		return $this;
52
	}
53
54
55
	/**
56
	 * @return string
57
	 * @throws QueryException
58
	 */
59
	private function getDistinctSyntax()
60
	{
61
		$useDistinct = $this->queryStructure->getElement( QueryStructure::DISTINCT );
62
63
		switch ( $useDistinct ) {
64
			case 0:
65
				return '';
66
			case 1:
67
				return 'DISTINCT';
68
			case 2:
69
				return 'DISTINCTROW';
70
			default:
71
				throw new QueryException( 'Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT );
72
		}
73
74
	}
75
76
77
}