1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Willry\QueryBuilder; |
4
|
|
|
|
5
|
|
|
class Query extends Base |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @param string $columns |
10
|
|
|
* @return $this |
11
|
|
|
*/ |
12
|
|
|
public function selectRaw(string $columns = "*", array $params = []): self |
13
|
|
|
{ |
14
|
|
|
$this->setBindings($params, 'select'); |
15
|
|
|
$this->columns = array_merge($this->columns, explode(',', $columns)); |
16
|
|
|
return $this; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function select(array $columns = ['*']): self |
20
|
|
|
{ |
21
|
|
|
$this->columns = array_merge($this->columns, $columns); |
22
|
|
|
return $this; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $columnOrder |
27
|
|
|
*/ |
28
|
|
|
public function order(string $columnOrder): self |
29
|
|
|
{ |
30
|
|
|
$this->order = "ORDER BY ?"; |
31
|
|
|
$this->setBindings([$columnOrder], 'order'); |
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $group |
37
|
|
|
* @return DB |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
public function groupBy(string $group): self |
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
$this->groupBy = "GROUP BY {$group}"; |
43
|
|
|
return $this; |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $having |
48
|
|
|
* @return DB |
49
|
|
|
*/ |
50
|
|
|
public function having(string $having, array $params = []): self |
51
|
|
|
{ |
52
|
|
|
$this->having = "HAVING {$having}"; |
53
|
|
|
$this->setBindings($params, 'having'); |
54
|
|
|
return $this; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $limit |
59
|
|
|
*/ |
60
|
|
|
public function limit(int $limit): static |
61
|
|
|
{ |
62
|
|
|
$this->limit = "LIMIT $limit"; |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $offset |
68
|
|
|
* @return DB |
69
|
|
|
*/ |
70
|
|
|
public function offset(int $offset): static |
71
|
|
|
{ |
72
|
|
|
$this->offset = "OFFSET $offset"; |
73
|
|
|
return $this; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function get(): ?array |
77
|
|
|
{ |
78
|
|
|
$this->mountQuery(); |
79
|
|
|
|
80
|
|
|
try { |
81
|
|
|
$stmt = $this->db->prepare($this->query); |
82
|
|
|
QueryHelpers::bind($stmt, $this->flatBindings()); |
83
|
|
|
$stmt->execute(); |
84
|
|
|
|
85
|
|
|
return $stmt->fetchAll(\PDO::FETCH_CLASS); |
86
|
|
|
} catch (\PDOException $exception) { |
87
|
|
|
$this->handleError($exception); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function first(): ?\stdClass |
92
|
|
|
{ |
93
|
|
|
$this->mountQuery(); |
94
|
|
|
|
95
|
|
|
try { |
96
|
|
|
$stmt = $this->db->prepare($this->query); |
97
|
|
|
QueryHelpers::bind($stmt, $this->flatBindings()); |
98
|
|
|
$stmt->execute(); |
99
|
|
|
|
100
|
|
|
if (!$stmt->rowCount()) { |
101
|
|
|
return null; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $stmt->fetchObject(); |
105
|
|
|
} catch (\PDOException $exception) { |
106
|
|
|
$this->handleError($exception); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function count(): ?int |
111
|
|
|
{ |
112
|
|
|
$this->mountQuery(); |
113
|
|
|
|
114
|
|
|
try { |
115
|
|
|
$stmt = $this->db->prepare($this->query); |
116
|
|
|
QueryHelpers::bind($stmt, $this->flatBindings()); |
117
|
|
|
$stmt->execute(); |
118
|
|
|
|
119
|
|
|
return $stmt->rowCount(); |
120
|
|
|
} catch (\PDOException $exception) { |
121
|
|
|
$this->handleError($exception); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths