|
1
|
|
|
<?php declare (strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* @license MIT |
|
4
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace EmmetBlue\Core\Builder\QueryBuilder; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* class SelectQueryBuilder. |
|
10
|
|
|
* Builds an Select query. |
|
11
|
|
|
* |
|
12
|
|
|
* {@see QueryBuilder} |
|
13
|
|
|
* |
|
14
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
15
|
|
|
* |
|
16
|
|
|
* @since 28/05/2016 |
|
17
|
|
|
*/ |
|
18
|
|
|
class SelectQueryBuilder extends QueryBuilder |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \EmmetBlue\Core\Builder\QueryBuilder |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $queryBuilder; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string|null $tableName |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$SelectKeyword = "SELECT"; |
|
31
|
|
|
$this->queryBuilder = $this->build($SelectKeyword); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
* |
|
37
|
|
|
* @param int $topValue |
|
38
|
|
|
* |
|
39
|
|
|
* @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
40
|
|
|
*/ |
|
41
|
|
|
public function top(int $topValue) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->queryBuilder = $this->queryBuilder->build("TOP ".$topValue); |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
/** |
|
48
|
|
|
* This method handles situations that requires to |
|
49
|
|
|
* select all from the table. |
|
50
|
|
|
* @param * |
|
51
|
|
|
*/ |
|
52
|
|
|
public function all() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->queryBuilder = $this->queryBuilder->build("*"); |
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $columns |
|
61
|
|
|
* |
|
62
|
|
|
* @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
63
|
|
|
*/ |
|
64
|
|
|
public function columns(string ...$columns) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->queryBuilder = $this->queryBuilder->build(self::getImplodedString($columns)); |
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $tableName |
|
75
|
|
|
* |
|
76
|
|
|
* @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
77
|
|
|
*/ |
|
78
|
|
|
public function from(string $tableName) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->queryBuilder = $this->queryBuilder->build("FROM ".$tableName); |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $tableName |
|
89
|
|
|
* @param string $condition |
|
90
|
|
|
* |
|
91
|
|
|
* @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
92
|
|
|
*/ |
|
93
|
|
|
public function innerJoin(string $tableName, string $condition) |
|
94
|
|
|
{ |
|
95
|
|
|
$string = "INNER JOIN ".$tableName." ON ".$condition; |
|
96
|
|
|
$this->queryBuilder = $this->queryBuilder->build($string); |
|
97
|
|
|
|
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.