Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 2 |
Changes | 0 |
Metric | Value |
---|---|
cc | 2 |
eloc | 7 |
nc | 2 |
nop | 3 |
dl | 0 |
loc | 13 |
ccs | 8 |
cts | 8 |
cp | 1 |
crap | 2 |
rs | 10 |
c | 0 |
b | 0 |
f | 0 |
1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | namespace Triadev\Leopard\Business\Dsl\Aggregation; |
||
0 ignored issues
–
show
|
|||
3 | |||
4 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\ChildrenAggregation; |
||
5 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation; |
||
6 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateRangeAggregation; |
||
7 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DiversifiedSamplerAggregation; |
||
8 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FilterAggregation; |
||
9 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FiltersAggregation; |
||
10 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoDistanceAggregation; |
||
11 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoHashGridAggregation; |
||
12 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\HistogramAggregation; |
||
13 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\Ipv4RangeAggregation; |
||
14 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\MissingAggregation; |
||
15 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\NestedAggregation; |
||
16 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\RangeAggregation; |
||
17 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SamplerAggregation; |
||
18 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SignificantTermsAggregation; |
||
19 | use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; |
||
20 | use ONGR\ElasticsearchDSL\BuilderInterface; |
||
21 | |||
22 | class Bucketing extends Aggs |
||
0 ignored issues
–
show
|
|||
23 | { |
||
0 ignored issues
–
show
|
|||
24 | /** |
||
25 | * Children |
||
26 | * |
||
27 | * @param string $name |
||
0 ignored issues
–
show
|
|||
28 | * @param string $children |
||
0 ignored issues
–
show
|
|||
29 | * @param \Closure $bucketing |
||
0 ignored issues
–
show
|
|||
30 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
31 | */ |
||
32 | 1 | public function children(string $name, string $children, \Closure $bucketing) : Bucketing |
|
0 ignored issues
–
show
|
|||
33 | { |
||
34 | 1 | $resultAgg = new ChildrenAggregation($name, $children); |
|
35 | |||
36 | 1 | $bucketingBuilder = new self(); |
|
37 | 1 | $bucketing($bucketingBuilder); |
|
38 | |||
39 | 1 | foreach ($bucketingBuilder->getAggregations() as $agg) { |
|
40 | 1 | $resultAgg->addAggregation($agg); |
|
41 | } |
||
42 | |||
43 | 1 | $this->addAggregation($resultAgg); |
|
44 | 1 | return $this; |
|
45 | } |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | /** |
||
48 | * Date histogram |
||
49 | * |
||
50 | * @param string $name |
||
0 ignored issues
–
show
|
|||
51 | * @param string $field |
||
0 ignored issues
–
show
|
|||
52 | * @param string $interval |
||
0 ignored issues
–
show
|
|||
53 | * @param string|null $format |
||
0 ignored issues
–
show
|
|||
54 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
55 | * |
||
56 | * @throws \InvalidArgumentException |
||
0 ignored issues
–
show
|
|||
57 | */ |
||
58 | 1 | public function dateHistogram( |
|
59 | string $name, |
||
60 | string $field, |
||
61 | string $interval, |
||
62 | ?string $format = null |
||
0 ignored issues
–
show
|
|||
63 | ) : Bucketing { |
||
0 ignored issues
–
show
|
|||
64 | $validInterval = [ |
||
65 | 1 | 'year', |
|
1 ignored issue
–
show
|
|||
66 | 'quarter', |
||
1 ignored issue
–
show
|
|||
67 | 'month', |
||
1 ignored issue
–
show
|
|||
68 | 'week', |
||
1 ignored issue
–
show
|
|||
69 | 'day', |
||
1 ignored issue
–
show
|
|||
70 | 'hour', |
||
1 ignored issue
–
show
|
|||
71 | 'minute', |
||
1 ignored issue
–
show
|
|||
72 | 'second' |
||
0 ignored issues
–
show
|
|||
73 | ]; |
||
0 ignored issues
–
show
|
|||
74 | |||
75 | 1 | if (!in_array($interval, $validInterval)) { |
|
0 ignored issues
–
show
|
|||
76 | throw new \InvalidArgumentException(); |
||
77 | } |
||
78 | |||
79 | 1 | $this->addAggregation(new DateHistogramAggregation($name, $field, $interval, $format)); |
|
80 | 1 | return $this; |
|
81 | } |
||
0 ignored issues
–
show
|
|||
82 | |||
83 | /** |
||
84 | * Date range |
||
85 | * |
||
86 | * @param string $name |
||
0 ignored issues
–
show
|
|||
87 | * @param string $field |
||
0 ignored issues
–
show
|
|||
88 | * @param string $format |
||
0 ignored issues
–
show
|
|||
89 | * @param array $ranges |
||
0 ignored issues
–
show
|
|||
90 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
91 | */ |
||
92 | 1 | public function dateRange( |
|
93 | string $name, |
||
94 | string $field, |
||
95 | string $format, |
||
96 | array $ranges = [] |
||
0 ignored issues
–
show
|
|||
97 | ) : Bucketing { |
||
0 ignored issues
–
show
|
|||
98 | 1 | $this->addAggregation(new DateRangeAggregation($name, $field, $format, $ranges)); |
|
99 | 1 | return $this; |
|
100 | } |
||
0 ignored issues
–
show
|
|||
101 | |||
102 | /** |
||
103 | * Diversified sampler |
||
104 | * |
||
105 | * @param string $name |
||
0 ignored issues
–
show
|
|||
106 | * @param string $field |
||
0 ignored issues
–
show
|
|||
107 | * @param int|null $shardSize |
||
0 ignored issues
–
show
|
|||
108 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
109 | */ |
||
110 | 1 | public function diversifiedSampler(string $name, string $field, ?int $shardSize = null) : Bucketing |
|
0 ignored issues
–
show
|
|||
111 | { |
||
112 | 1 | $this->addAggregation(new DiversifiedSamplerAggregation($name, $field, $shardSize)); |
|
113 | 1 | return $this; |
|
114 | } |
||
0 ignored issues
–
show
|
|||
115 | |||
116 | /** |
||
117 | * Filter |
||
118 | * |
||
119 | * @param string $name |
||
0 ignored issues
–
show
|
|||
120 | * @param BuilderInterface $aggregation |
||
0 ignored issues
–
show
|
|||
121 | * @param BuilderInterface[] $aggregations |
||
0 ignored issues
–
show
|
|||
122 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
123 | */ |
||
124 | 1 | public function filter(string $name, BuilderInterface $aggregation, array $aggregations) : Bucketing |
|
0 ignored issues
–
show
|
|||
125 | { |
||
126 | 1 | $agg = new FilterAggregation($name, $aggregation); |
|
127 | |||
128 | 1 | foreach ($aggregations as $a) { |
|
129 | 1 | if ($a instanceof BuilderInterface) { |
|
130 | 1 | $agg->addAggregation($a); |
|
131 | } |
||
132 | } |
||
133 | |||
134 | 1 | $this->addAggregation($agg); |
|
135 | 1 | return $this; |
|
136 | } |
||
0 ignored issues
–
show
|
|||
137 | |||
138 | /** |
||
139 | * Filters |
||
140 | * |
||
141 | * @param string $name |
||
0 ignored issues
–
show
|
|||
142 | * @param BuilderInterface[] $filters |
||
0 ignored issues
–
show
|
|||
143 | * @param BuilderInterface[] $aggregations |
||
0 ignored issues
–
show
|
|||
144 | * @param bool $anonymous |
||
0 ignored issues
–
show
|
|||
145 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
146 | */ |
||
147 | 1 | public function filters(string $name, array $filters, array $aggregations, bool $anonymous = false) : Bucketing |
|
0 ignored issues
–
show
|
|||
148 | { |
||
149 | 1 | $agg = new FiltersAggregation($name, $filters, $anonymous); |
|
150 | |||
151 | 1 | foreach ($aggregations as $a) { |
|
152 | 1 | if ($a instanceof BuilderInterface) { |
|
153 | 1 | $agg->addAggregation($a); |
|
154 | } |
||
155 | } |
||
156 | |||
157 | 1 | $this->addAggregation($agg); |
|
158 | |||
159 | 1 | return $this; |
|
160 | } |
||
0 ignored issues
–
show
|
|||
161 | |||
162 | /** |
||
163 | * Geo distance |
||
164 | * |
||
165 | * @param string $name |
||
0 ignored issues
–
show
|
|||
166 | * @param string $field |
||
0 ignored issues
–
show
|
|||
167 | * @param string $origin |
||
0 ignored issues
–
show
|
|||
168 | * @param array $ranges |
||
0 ignored issues
–
show
|
|||
169 | * @param string|null $unit |
||
0 ignored issues
–
show
|
|||
170 | * @param string|null $distanceType |
||
0 ignored issues
–
show
|
|||
171 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
172 | */ |
||
173 | 1 | public function geoDistance( |
|
174 | string $name, |
||
175 | string $field, |
||
176 | string $origin, |
||
177 | array $ranges = [], |
||
0 ignored issues
–
show
|
|||
178 | string $unit = null, |
||
0 ignored issues
–
show
|
|||
179 | string $distanceType = null |
||
0 ignored issues
–
show
|
|||
180 | ) : Bucketing { |
||
0 ignored issues
–
show
|
|||
181 | 1 | $this->addAggregation(new GeoDistanceAggregation( |
|
1 ignored issue
–
show
|
|||
182 | 1 | $name, |
|
183 | 1 | $field, |
|
184 | 1 | $origin, |
|
185 | 1 | $ranges, |
|
186 | 1 | $unit, |
|
187 | 1 | $distanceType |
|
188 | )); |
||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
189 | 1 | return $this; |
|
190 | } |
||
0 ignored issues
–
show
|
|||
191 | |||
192 | /** |
||
193 | * Geo hash grid |
||
194 | * |
||
195 | * @param string $name |
||
0 ignored issues
–
show
|
|||
196 | * @param string $field |
||
0 ignored issues
–
show
|
|||
197 | * @param int|null $precision |
||
0 ignored issues
–
show
|
|||
198 | * @param int|null $size |
||
0 ignored issues
–
show
|
|||
199 | * @param int|null $shardSize |
||
0 ignored issues
–
show
|
|||
200 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
201 | */ |
||
202 | 1 | public function geoHashGrid( |
|
203 | string $name, |
||
204 | string $field, |
||
205 | ?int $precision = null, |
||
0 ignored issues
–
show
|
|||
206 | ?int $size = null, |
||
0 ignored issues
–
show
|
|||
207 | ?int $shardSize = null |
||
0 ignored issues
–
show
|
|||
208 | ) : Bucketing { |
||
0 ignored issues
–
show
|
|||
209 | 1 | $this->addAggregation(new GeoHashGridAggregation( |
|
1 ignored issue
–
show
|
|||
210 | 1 | $name, |
|
211 | 1 | $field, |
|
212 | 1 | $precision, |
|
213 | 1 | $size, |
|
214 | 1 | $shardSize |
|
215 | )); |
||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
216 | 1 | return $this; |
|
217 | } |
||
0 ignored issues
–
show
|
|||
218 | |||
219 | /** |
||
220 | * Histogram |
||
221 | * |
||
222 | * @param string $name |
||
0 ignored issues
–
show
|
|||
223 | * @param string $field |
||
0 ignored issues
–
show
|
|||
224 | * @param int $interval |
||
0 ignored issues
–
show
|
|||
225 | * @param int|null $minDocCount |
||
0 ignored issues
–
show
|
|||
226 | * @param string|null $orderMode |
||
0 ignored issues
–
show
|
|||
227 | * @param string $orderDirection |
||
0 ignored issues
–
show
|
|||
228 | * @param int|null $extendedBoundsMin |
||
0 ignored issues
–
show
|
|||
229 | * @param int|null $extendedBoundsMax |
||
0 ignored issues
–
show
|
|||
230 | * @param bool|null $keyed |
||
0 ignored issues
–
show
|
|||
231 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
232 | */ |
||
233 | 1 | public function histogram( |
|
234 | string $name, |
||
235 | string $field, |
||
236 | int $interval, |
||
237 | ?int $minDocCount = null, |
||
0 ignored issues
–
show
|
|||
238 | ?string $orderMode = null, |
||
0 ignored issues
–
show
|
|||
239 | string $orderDirection = HistogramAggregation::DIRECTION_ASC, |
||
0 ignored issues
–
show
|
|||
240 | ?int $extendedBoundsMin = null, |
||
0 ignored issues
–
show
|
|||
241 | ?int $extendedBoundsMax = null, |
||
0 ignored issues
–
show
|
|||
242 | bool $keyed = null |
||
0 ignored issues
–
show
|
|||
243 | ) : Bucketing { |
||
0 ignored issues
–
show
|
|||
244 | 1 | $this->addAggregation(new HistogramAggregation( |
|
1 ignored issue
–
show
|
|||
245 | 1 | $name, |
|
246 | 1 | $field, |
|
247 | 1 | $interval, |
|
248 | 1 | $minDocCount, |
|
249 | 1 | $orderMode, |
|
250 | 1 | $orderDirection, |
|
251 | 1 | $extendedBoundsMin, |
|
252 | 1 | $extendedBoundsMax, |
|
253 | 1 | $keyed |
|
254 | )); |
||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
255 | 1 | return $this; |
|
256 | } |
||
0 ignored issues
–
show
|
|||
257 | |||
258 | /** |
||
259 | * Ipv4 |
||
260 | * |
||
261 | * @param string $name |
||
0 ignored issues
–
show
|
|||
262 | * @param string $field |
||
0 ignored issues
–
show
|
|||
263 | * @param array $ranges |
||
0 ignored issues
–
show
|
|||
264 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
265 | */ |
||
266 | 1 | public function ipv4Range(string $name, string $field, array $ranges = []) : Bucketing |
|
0 ignored issues
–
show
|
|||
267 | { |
||
268 | 1 | $this->addAggregation(new Ipv4RangeAggregation( |
|
1 ignored issue
–
show
|
|||
269 | 1 | $name, |
|
270 | 1 | $field, |
|
271 | 1 | $ranges |
|
272 | )); |
||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
273 | 1 | return $this; |
|
274 | } |
||
0 ignored issues
–
show
|
|||
275 | |||
276 | /** |
||
277 | * Missing |
||
278 | * |
||
279 | * @param string $name |
||
0 ignored issues
–
show
|
|||
280 | * @param string $field |
||
0 ignored issues
–
show
|
|||
281 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
282 | */ |
||
283 | 1 | public function missing(string $name, string $field) : Bucketing |
|
284 | { |
||
285 | 1 | $this->addAggregation(new MissingAggregation($name, $field)); |
|
286 | 1 | return $this; |
|
287 | } |
||
0 ignored issues
–
show
|
|||
288 | |||
289 | /** |
||
290 | * Nested |
||
291 | * |
||
292 | * @param string $name |
||
0 ignored issues
–
show
|
|||
293 | * @param string $path |
||
0 ignored issues
–
show
|
|||
294 | * @param array $aggregations |
||
0 ignored issues
–
show
|
|||
295 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
296 | */ |
||
297 | 1 | public function nested(string $name, string $path, array $aggregations = []) : Bucketing |
|
0 ignored issues
–
show
|
|||
298 | { |
||
299 | 1 | $agg = new NestedAggregation($name, $path); |
|
300 | |||
301 | 1 | foreach ($aggregations as $aggregation) { |
|
302 | 1 | if ($aggregation instanceof BuilderInterface) { |
|
303 | 1 | $agg->addAggregation($aggregation); |
|
304 | } |
||
305 | } |
||
306 | |||
307 | 1 | $this->addAggregation($agg); |
|
308 | 1 | return $this; |
|
309 | } |
||
0 ignored issues
–
show
|
|||
310 | |||
311 | /** |
||
312 | * Range |
||
313 | * |
||
314 | * @param string $name |
||
0 ignored issues
–
show
|
|||
315 | * @param string $field |
||
0 ignored issues
–
show
|
|||
316 | * @param array $ranges |
||
0 ignored issues
–
show
|
|||
317 | * @param bool $keyed |
||
0 ignored issues
–
show
|
|||
318 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
319 | */ |
||
320 | 1 | public function range(string $name, string $field, array $ranges = [], bool $keyed = false) : Bucketing |
|
0 ignored issues
–
show
|
|||
321 | { |
||
322 | 1 | $this->addAggregation(new RangeAggregation($name, $field, $ranges, $keyed)); |
|
323 | 1 | return $this; |
|
324 | } |
||
0 ignored issues
–
show
|
|||
325 | |||
326 | public function reverseNested() : Bucketing |
||
0 ignored issues
–
show
|
|||
327 | { |
||
328 | return $this; |
||
329 | } |
||
0 ignored issues
–
show
|
|||
330 | |||
331 | /** |
||
332 | * Sampler |
||
333 | * |
||
334 | * @param string $name |
||
0 ignored issues
–
show
|
|||
335 | * @param string $field |
||
0 ignored issues
–
show
|
|||
336 | * @param int|null $shardSize |
||
0 ignored issues
–
show
|
|||
337 | * @param array $aggregations |
||
0 ignored issues
–
show
|
|||
338 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
339 | */ |
||
340 | 1 | public function sampler(string $name, string $field, ?int $shardSize = null, array $aggregations = []) : Bucketing |
|
0 ignored issues
–
show
|
|||
341 | { |
||
342 | 1 | $agg = new SamplerAggregation($name, $field, $shardSize); |
|
343 | |||
344 | 1 | foreach ($aggregations as $aggregation) { |
|
345 | 1 | if ($aggregation instanceof BuilderInterface) { |
|
346 | 1 | $agg->addAggregation($aggregation); |
|
347 | } |
||
348 | } |
||
349 | |||
350 | 1 | $this->addAggregation($agg); |
|
351 | 1 | return $this; |
|
352 | } |
||
0 ignored issues
–
show
|
|||
353 | |||
354 | /** |
||
355 | * Significant terms |
||
356 | * |
||
357 | * @param string $name |
||
0 ignored issues
–
show
|
|||
358 | * @param string $field |
||
0 ignored issues
–
show
|
|||
359 | * @param string|null $script |
||
0 ignored issues
–
show
|
|||
360 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
361 | */ |
||
362 | 1 | public function significantTerms(string $name, string $field, ?string $script = null) : Bucketing |
|
0 ignored issues
–
show
|
|||
363 | { |
||
364 | 1 | $this->addAggregation(new SignificantTermsAggregation($name, $field, $script)); |
|
365 | 1 | return $this; |
|
366 | } |
||
0 ignored issues
–
show
|
|||
367 | |||
368 | /** |
||
369 | * Terms |
||
370 | * |
||
371 | * @param string $name |
||
0 ignored issues
–
show
|
|||
372 | * @param string|null $field |
||
0 ignored issues
–
show
|
|||
373 | * @param string|null $script |
||
0 ignored issues
–
show
|
|||
374 | * @return Bucketing |
||
0 ignored issues
–
show
|
|||
375 | */ |
||
376 | 2 | public function terms(string $name, ?string $field = null, ?string $script = null) : Bucketing |
|
0 ignored issues
–
show
|
|||
377 | { |
||
378 | 2 | $this->addAggregation(new TermsAggregation($name, $field, $script)); |
|
379 | 2 | return $this; |
|
380 | } |
||
0 ignored issues
–
show
|
|||
381 | } |
||
0 ignored issues
–
show
|
|||
382 |