|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sanderdekroon\Parlant\Builder; |
|
4
|
|
|
|
|
5
|
|
|
trait BuildsQueries |
|
6
|
|
|
{ |
|
7
|
|
|
protected $grammar; |
|
8
|
|
|
protected $compiler; |
|
9
|
|
|
protected $bindings; |
|
10
|
|
|
protected $configuration; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Get the posts by passing the bindings, configuration and building the arguments. |
|
14
|
|
|
* @return mixed |
|
15
|
|
|
*/ |
|
16
|
25 |
|
public function get() |
|
17
|
|
|
{ |
|
18
|
25 |
|
return $this->compiler |
|
19
|
25 |
|
->bind($this->bindings) |
|
20
|
25 |
|
->withConfiguration($this->configuration) |
|
21
|
25 |
|
->build(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Return only the first post. |
|
26
|
|
|
* @return \WP_Post |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function first() |
|
29
|
|
|
{ |
|
30
|
1 |
|
$this->setBinding('posts_per_page', 1); |
|
|
|
|
|
|
31
|
1 |
|
$posts = $this->get(); |
|
32
|
|
|
|
|
33
|
|
|
// If the developer has requested the argument list, we'll return the full array. |
|
34
|
1 |
|
if ($this->configuration->get('return') == 'argument') { |
|
35
|
1 |
|
return $posts; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// If it's an array, we'll assume it's one post wrapped within an array. |
|
39
|
|
|
// Anything else just gets returned without modification. |
|
40
|
|
|
return is_array($posts) ? reset($posts) : $posts; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Return all posts with no limit. |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public function all() |
|
48
|
|
|
{ |
|
49
|
3 |
|
$this->setBinding('posts_per_page', -1); |
|
|
|
|
|
|
50
|
3 |
|
return $this->get(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Count the total of found posts. |
|
55
|
|
|
* @return int |
|
56
|
|
|
*/ |
|
57
|
|
|
public function count() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->configuration->add('return', 'Sanderdekroon\Parlant\Formatter\CountFormatter'); |
|
60
|
|
|
return $this->get(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Pluck the values of the supplied column name |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
public function pluck(string $columnname) |
|
68
|
|
|
{ |
|
69
|
|
|
if (!in_array($columnname, $this->grammar->getPostProperties())) { |
|
70
|
|
|
throw new \InvalidArgumentException('Invalid columnname '.$columnname); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->configuration->add('return', 'Sanderdekroon\Parlant\Formatter\ArrayFormatter'); |
|
74
|
|
|
|
|
75
|
|
|
return array_map(function ($post) use ($columnname) { |
|
76
|
|
|
return $post->$columnname; |
|
77
|
|
|
}, $this->get()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @todo Implement |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function avg() |
|
84
|
|
|
{ |
|
85
|
1 |
|
throw new \BadMethodCallException('Accessing unimplemented method.'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @todo Implement |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function max() |
|
92
|
|
|
{ |
|
93
|
1 |
|
throw new \BadMethodCallException('Accessing unimplemented method.'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @todo Implement |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function min() |
|
100
|
|
|
{ |
|
101
|
1 |
|
throw new \BadMethodCallException('Accessing unimplemented method.'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
protected abstract function setBinding(); |
|
106
|
|
|
} |
|
107
|
|
|
|
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