JsonDecoding::decode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Json;
5
6
use function json_decode;
7
use const JSON_ERROR_NONE;
8
use function json_last_error;
9
use function json_last_error_msg;
10
11
trait JsonDecoding
12
{
13
    /** @throws InvalidJson */
14
    private static function decode(string $input)
15
    {
16
        $decoded = json_decode($input, true);
17
        if (json_last_error() !== JSON_ERROR_NONE) {
18
            throw InputStringIsInvalid::detected(json_last_error_msg(), $input);
19
        }
20
        return $decoded;
21
    }
22
}
23
24