Skip to content

Commit 70d67bc

Browse files
authored
Fix PHPStan error introduced with latest phpstan release (#35)
1 parent ec124c7 commit 70d67bc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Prometheus/Storage/APC.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,35 @@ private function collectHistograms(): array
335335
/**
336336
* @param mixed $val
337337
* @return int
338+
* @throws RuntimeException
338339
*/
339340
private function toBinaryRepresentationAsInteger($val): int
340341
{
341-
return unpack('Q', pack('d', $val))[1];
342+
$packedDouble = pack('d', $val);
343+
if ((bool)$packedDouble !== false) {
344+
$unpackedData = unpack("Q", $packedDouble);
345+
if (is_array($unpackedData)) {
346+
return $unpackedData[1];
347+
}
348+
}
349+
throw new RuntimeException("Formatting from binary representation to integer did not work");
342350
}
343351

344352
/**
345353
* @param mixed $val
346354
* @return float
355+
* @throws RuntimeException
347356
*/
348357
private function fromBinaryRepresentationAsInteger($val): float
349358
{
350-
return unpack('d', pack('Q', $val))[1];
359+
$packedBinary = pack('Q', $val);
360+
if ((bool)$packedBinary !== false) {
361+
$unpackedData = unpack("d", $packedBinary);
362+
if (is_array($unpackedData)) {
363+
return $unpackedData[1];
364+
}
365+
}
366+
throw new RuntimeException("Formatting from integer to binary representation did not work");
351367
}
352368

353369
/**

0 commit comments

Comments
 (0)