for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Stratadox\Json;
use function json_decode;
use const JSON_ERROR_NONE;
use function json_last_error;
use function json_last_error_msg;
trait JsonDecoding
{
/** @throws InvalidJson */
private static function decode(string $input)
$decoded = json_decode($input, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw InputStringIsInvalid::detected(json_last_error_msg(), $input);
}
return $decoded;