Skip to content

Commit a0e98a2

Browse files
committed
Added ability to get float value
1 parent 020e4f2 commit a0e98a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Response/Result/Hit.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,30 @@ public function getIntegerOrNullValue(string $key): int|null
175175
}
176176

177177

178+
public function getFloatValue(string $key): float
179+
{
180+
if (
181+
isset($this->source[$key])
182+
&& \is_float($this->source[$key]) === TRUE
183+
) {
184+
return $this->source[$key];
185+
}
186+
187+
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(\sprintf('Value for key %s is not float.', $key));
188+
}
189+
190+
191+
public function getFloatOrNullValue(string $key): float|null
192+
{
193+
try {
194+
return $this->getFloatValue($key);
195+
196+
} catch (\Spameri\ElasticQuery\Exception\InvalidArgumentException $exception) {
197+
return NULL;
198+
}
199+
}
200+
201+
178202
/**
179203
* @phpstan-return mixed
180204
*/

0 commit comments

Comments
 (0)