Skip to content

Commit c6d9c1e

Browse files
authored
Merge pull request #2 from bistrosk/8.0
fix empty objects being normalized as arrays
2 parents 850fdbc + 2f05d5a commit c6d9c1e

File tree

90 files changed

+102
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+102
-102
lines changed

src/Aggregation/AbstractAggregation.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract protected function supportsNesting(): bool;
4141
/**
4242
* @return array|\stdClass
4343
*/
44-
abstract public function getArray(): array;
44+
abstract public function getArray(): array|\stdClass;
4545

4646
/**
4747
* Inner aggregations container init.
@@ -122,11 +122,11 @@ public function getAggregation($name)
122122
/**
123123
* {@inheritdoc}
124124
*/
125-
public function toArray(): array
125+
public function toArray(): array|\stdClass
126126
{
127127
$array = $this->getArray();
128128
$result = [
129-
$this->getType() => $this->processArray($array),
129+
$this->getType() => is_array($array) ? $this->processArray($array) : $array,
130130
];
131131

132132
if ($this->supportsNesting()) {

src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function addFilter(string $name, BuilderInterface $filter): static
6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function getArray(): array
64+
public function getArray(): array|\stdClass
6565
{
6666
return $this->filters;
6767
}

src/Aggregation/Bucketing/AutoDateHistogramAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(string $name, $field, $buckets = null, $format = nul
5050
/**
5151
* {@inheritdoc}
5252
*/
53-
public function getArray(): array
53+
public function getArray(): array|\stdClass
5454
{
5555
return array_filter(
5656
[

src/Aggregation/Bucketing/ChildrenAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getType(): string
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function getArray(): array
58+
public function getArray(): array|\stdClass
5959
{
6060
if (count($this->getAggregations()) == 0) {
6161
throw new \LogicException(sprintf('Children aggregation `%s` has no aggregations added', $this->getName()));

src/Aggregation/Bucketing/CompositeAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function addSource(AbstractAggregation $agg): static
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
public function getArray(): array
66+
public function getArray(): array|\stdClass
6767
{
6868
$array = [
6969
'sources' => $this->sources,

src/Aggregation/Bucketing/DateHistogramAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getType(): string
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function getArray(): array
71+
public function getArray(): array|\stdClass
7272
{
7373
if (!$this->getField() || !$this->getInterval()) {
7474
throw new \LogicException('Date histogram aggregation must have field and interval set.');

src/Aggregation/Bucketing/DateRangeAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function addRange(mixed $from = null, mixed $to = null, mixed $key = null
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
public function getArray(): array
101+
public function getArray(): array|\stdClass
102102
{
103103
if ($this->getField() && $this->getFormat() && !empty($this->ranges)) {
104104
return [

src/Aggregation/Bucketing/DiversifiedSamplerAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getType(): string
7373
/**
7474
* @inheritdoc
7575
*/
76-
public function getArray(): array
76+
public function getArray(): array|\stdClass
7777
{
7878
return array_filter(
7979
[

src/Aggregation/Bucketing/FilterAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function setField($field): void
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function getArray(): array
70+
public function getArray(): array|\stdClass
7171
{
7272
if (!$this->filter) {
7373
throw new \LogicException(sprintf('Filter aggregation `%s` has no filter added', $this->getName()));

src/Aggregation/Bucketing/FiltersAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function addFilter(BuilderInterface $filter, string $name = ''): static
7878
/**
7979
* {@inheritdoc}
8080
*/
81-
public function getArray(): array
81+
public function getArray(): array|\stdClass
8282
{
8383
return $this->filters;
8484
}

src/Aggregation/Bucketing/GeoDistanceAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function addRange(mixed $from = null, mixed $to = null): static
122122
/**
123123
* {@inheritdoc}
124124
*/
125-
public function getArray(): array
125+
public function getArray(): array|\stdClass
126126
{
127127
$data = [];
128128

src/Aggregation/Bucketing/GeoHashGridAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function setShardSize($shardSize)
120120
/**
121121
* {@inheritdoc}
122122
*/
123-
public function getArray(): array
123+
public function getArray(): array|\stdClass
124124
{
125125
$data = [];
126126

src/Aggregation/Bucketing/GlobalAggregation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function getType(): string
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function getArray(): array
45+
public function getArray(): array|\stdClass
4646
{
47-
return [];
47+
return new \stdClass();
4848
}
4949
}

src/Aggregation/Bucketing/HistogramAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function getType(): string
218218
/**
219219
* {@inheritdoc}
220220
*/
221-
public function getArray(): array
221+
public function getArray(): array|\stdClass
222222
{
223223
$out = array_filter(
224224
[

src/Aggregation/Bucketing/Ipv4RangeAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getType(): string
8383
/**
8484
* {@inheritdoc}
8585
*/
86-
public function getArray(): array
86+
public function getArray(): array|\stdClass
8787
{
8888
if ($this->getField() && !empty($this->ranges)) {
8989
return [

src/Aggregation/Bucketing/MissingAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(string $name, mixed $field = null)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function getArray(): array
39+
public function getArray(): array|\stdClass
4040
{
4141
if ($this->getField()) {
4242
return ['field' => $this->getField()];

src/Aggregation/Bucketing/NestedAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getType(): string
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function getArray(): array
77+
public function getArray(): array|\stdClass
7878
{
7979
return ['path' => $this->getPath()];
8080
}

src/Aggregation/Bucketing/RangeAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function removeRangeByKey(string $key): bool
112112
/**
113113
* {@inheritdoc}
114114
*/
115-
public function getArray(): array
115+
public function getArray(): array|\stdClass
116116
{
117117
$data = [
118118
'keyed' => $this->keyed,

src/Aggregation/Bucketing/ReverseNestedAggregation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function getType(): string
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function getArray(): array
71+
public function getArray(): array|\stdClass
7272
{
73-
$output = [];
73+
$output = new \stdClass();
7474
if ($this->getPath()) {
7575
$output = ['path' => $this->getPath()];
7676
}

src/Aggregation/Bucketing/SamplerAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getType(): string
7575
/**
7676
* {@inheritdoc}
7777
*/
78-
public function getArray(): array
78+
public function getArray(): array|\stdClass
7979
{
8080
return array_filter(
8181
[

src/Aggregation/Bucketing/TermsAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getType(): string
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function getArray(): array
54+
public function getArray(): array|\stdClass
5555
{
5656
return array_filter(
5757
[

src/Aggregation/Matrix/MatrixStatsAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getType(): string
9292
return 'matrix_stats';
9393
}
9494

95-
public function getArray(): array
95+
public function getArray(): array|\stdClass
9696
{
9797
$out = [];
9898
if ($this->getField()) {

src/Aggregation/Metric/CardinalityAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CardinalityAggregation extends AbstractAggregation
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function getArray(): array
41+
public function getArray(): array|\stdClass
4242
{
4343
$out = array_filter(
4444
[

src/Aggregation/Metric/ExtendedStatsAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getType(): string
7878
/**
7979
* {@inheritdoc}
8080
*/
81-
public function getArray(): array
81+
public function getArray(): array|\stdClass
8282
{
8383
return array_filter(
8484
[

src/Aggregation/Metric/GeoBoundsAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function setWrapLongitude(bool $wrapLongitude): static
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function getArray(): array
57+
public function getArray(): array|\stdClass
5858
{
5959
$data = [];
6060
if ($this->getField()) {

src/Aggregation/Metric/GeoCentroidAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(string $name, ?string $field = null)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function getArray(): array
39+
public function getArray(): array|\stdClass
4040
{
4141
$data = [];
4242
if ($this->getField()) {

src/Aggregation/Metric/PercentileRanksAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getType(): string
105105
/**
106106
* {@inheritdoc}
107107
*/
108-
public function getArray(): array
108+
public function getArray(): array|\stdClass
109109
{
110110
$out = array_filter(
111111
[

src/Aggregation/Metric/PercentilesAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getType(): string
105105
/**
106106
* {@inheritdoc}
107107
*/
108-
public function getArray(): array
108+
public function getArray(): array|\stdClass
109109
{
110110
$out = array_filter(
111111
[

src/Aggregation/Metric/ScriptedMetricAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function setReduceScript(mixed $reduceScript)
151151
/**
152152
* {@inheritdoc}
153153
*/
154-
public function getArray(): array
154+
public function getArray(): array|\stdClass
155155
{
156156
return array_filter(
157157
[

src/Aggregation/Metric/StatsAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getType(): string
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function getArray(): array
50+
public function getArray(): array|\stdClass
5151
{
5252
$out = [];
5353
if ($this->getField()) {

src/Aggregation/Metric/TopHitsAggregation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function getType(): string
117117
/**
118118
* {@inheritdoc}
119119
*/
120-
public function getArray(): array
120+
public function getArray(): array|\stdClass
121121
{
122122
$sortsOutput = null;
123123
$addedSorts = array_filter($this->getSorts());
@@ -136,6 +136,6 @@ public function getArray(): array
136136
static fn($val): bool => $val || is_array($val) || ($val || is_numeric($val))
137137
);
138138

139-
return empty($output) ? [] : $output;
139+
return empty($output) ? new \stdClass() : $output;
140140
}
141141
}

src/Aggregation/Pipeline/AbstractPipelineAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function setBucketsPath($bucketsPath)
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function getArray(): array
50+
public function getArray(): array|\stdClass
5151
{
5252
return ['buckets_path' => $this->getBucketsPath()];
5353
}

src/Aggregation/Pipeline/BucketScriptAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getType(): string
5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function getArray(): array
55+
public function getArray(): array|\stdClass
5656
{
5757
if (!$this->getScript()) {
5858
throw new \LogicException(

src/Aggregation/Pipeline/BucketSortAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getType(): string
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function getArray(): array
71+
public function getArray(): array|\stdClass
7272
{
7373
return array_filter(
7474
[

src/Aggregation/Pipeline/PercentilesBucketAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function setPercents(array $percents)
4949
/**
5050
* {@inheritdoc}
5151
*/
52-
public function getArray(): array
52+
public function getArray(): array|\stdClass
5353
{
5454
$data = ['buckets_path' => $this->getBucketsPath()];
5555

src/BuilderBag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function all($type = null): array
106106
/**
107107
* {@inheritdoc}
108108
*/
109-
public function toArray(): array
109+
public function toArray(): array|\stdClass
110110
{
111111
$output = [];
112112
foreach ($this->all() as $builder) {

src/BuilderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface BuilderInterface
2121
*
2222
* @return array
2323
*/
24-
public function toArray(): array;
24+
public function toArray(): array|\stdClass;
2525

2626
/**
2727
* Returns element type.

src/Highlight/Highlight.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getType(): string
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function toArray(): array
61+
public function toArray(): array|\stdClass
6262
{
6363
$output = [];
6464

@@ -69,7 +69,7 @@ public function toArray(): array
6969
$output = $this->processArray($output);
7070

7171
foreach ($this->fields as $field => $params) {
72-
$output['fields'][$field] = count($params) ? $params : [];
72+
$output['fields'][$field] = count($params) ? $params : new \stdClass();
7373
}
7474

7575
return $output;

src/InnerHit/NestedInnerHit.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public function getType(): string
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function toArray(): array
80+
public function toArray(): array|\stdClass
8181
{
82-
$out = $this->getSearch() ? $this->getSearch()->toArray() : [];
82+
$out = $this->getSearch() ? $this->getSearch()->toArray() : new \stdClass();
8383

8484
return [
8585
$this->getPathType() => [

0 commit comments

Comments
 (0)