JsonDecoding   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 7 2
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