Skip to content

Commit c6bd7b8

Browse files
committed
get specific type values can extract subfields via dotted format
1 parent bb0cbc0 commit c6bd7b8

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/Response/Result/Hit.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public function getValue(
4040
public function getStringValue(string $key): string
4141
{
4242
if (
43-
isset($this->source[$key])
44-
&& \is_string($this->source[$key]) === true
43+
\is_string($this->getValue($key)) === true
4544
) {
46-
return $this->source[$key];
45+
return $this->getValue($key);
4746
}
4847

4948
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not string.', $key));
@@ -64,10 +63,9 @@ public function getStringOrNullValue(string $key): string|null
6463
public function getArrayValue(string $key): array
6564
{
6665
if (
67-
isset($this->source[$key])
68-
&& \is_array($this->source[$key]) === true
66+
\is_array($this->getValue($key)) === true
6967
) {
70-
return $this->source[$key];
68+
return $this->getValue($key);
7169
}
7270

7371
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not array.', $key));
@@ -88,10 +86,9 @@ public function getArrayOrNullValue(string $key): array|null
8886
public function getBoolValue(string $key): bool
8987
{
9088
if (
91-
isset($this->source[$key])
92-
&& \is_bool($this->source[$key]) === true
89+
\is_bool($this->getValue($key)) === true
9390
) {
94-
return $this->source[$key];
91+
return $this->getValue($key);
9592
}
9693

9794
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not bool.', $key));
@@ -112,10 +109,9 @@ public function getBoolOrNullValue(string $key): bool|null
112109
public function getIntegerValue(string $key): int
113110
{
114111
if (
115-
isset($this->source[$key])
116-
&& \is_int($this->source[$key]) === true
112+
\is_int($this->getValue($key)) === true
117113
) {
118-
return $this->source[$key];
114+
return $this->getValue($key);
119115
}
120116

121117
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not integer.', $key));
@@ -136,10 +132,9 @@ public function getIntegerOrNullValue(string $key): int|null
136132
public function getFloatValue(string $key): float
137133
{
138134
if (
139-
isset($this->source[$key])
140-
&& \is_float($this->source[$key]) === true
135+
\is_float($this->getValue($key)) === true
141136
) {
142-
return $this->source[$key];
137+
return $this->getValue($key);
143138
}
144139

145140
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not float.', $key));

0 commit comments

Comments
 (0)