Skip to content
Permalink
Browse files

Use JSON_THROW_ON_ERROR

  • Loading branch information...
LeSuisse committed Sep 13, 2019
1 parent 886cd58 commit 70a613573dea4626fc9343b4b9dbae65ed5b4e5f
Showing with 4 additions and 26 deletions.
  1. +2 −13 src/Storage/APCUStore.php
  2. +2 −13 src/Storage/InMemoryStore.php
@@ -26,7 +26,6 @@
use function implode;
use function json_decode;
use function json_encode;
use function json_last_error_msg;
use function pack;
use function sort;
use function strcmp;
@@ -371,15 +370,10 @@ private static function sortSamples(array &$samples) : void
/**
* @param string[] $values
*
* @throws RuntimeException
*/
private function encodeLabelValues(array $values) : string
{
$json = json_encode($values);
if ($json === false) {
throw new RuntimeException(json_last_error_msg());
}
$json = json_encode($values, JSON_THROW_ON_ERROR);
return base64_encode($json);
}
@@ -395,11 +389,6 @@ private function decodeLabelValues(string $values) : array
if ($json === false) {
throw new RuntimeException('Cannot base64 decode label values');
}
$decodedValues = json_decode($json, true);
if ($decodedValues === false) {
throw new RuntimeException(json_last_error_msg());
}
return $decodedValues;
return json_decode($json, true, JSON_THROW_ON_ERROR);
}
}
@@ -20,7 +20,6 @@
use function implode;
use function json_decode;
use function json_encode;
use function json_last_error_msg;
use function sort;
use function strcmp;
use function usort;
@@ -321,15 +320,10 @@ private function metaData(MetricName $name, string $help, LabelNames $labelNames
/**
* @param string[] $values
*
* @throws RuntimeException
*/
private function encodeLabelValues(array $values) : string
{
$json = json_encode($values);
if ($json === false) {
throw new RuntimeException(json_last_error_msg());
}
$json = json_encode($values, JSON_THROW_ON_ERROR);
return base64_encode($json);
}
@@ -345,11 +339,6 @@ private function decodeLabelValues(string $values) : array
if ($json === false) {
throw new RuntimeException('Cannot base64 decode label values');
}
$decodedValues = json_decode($json, true);
if ($decodedValues === false) {
throw new RuntimeException(json_last_error_msg());
}
return $decodedValues;
return json_decode($json, true, 512, JSON_THROW_ON_ERROR);
}
}

0 comments on commit 70a6135

Please sign in to comment.
You can’t perform that action at this time.