Completed
Pull Request — master (#18)
by Dominik
05:16
created

NativeJsonParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Decoder\Parsing;
6
7
final class NativeJsonParser implements JsonParserInterface
8
{
9
    /**
10
     * @param string $json
11
     * @return array|string|float|int|bool|null
12
     * @throws JsonParserException
13
     */
14
    public function parse(string $json)
15
    {
16
        $data = json_decode($json, true);
17
18
        if (JSON_ERROR_NONE !== json_last_error()) {
19
            throw JsonParserException::createFromError(json_last_error_msg());
20
        }
21
22
        return $data;
23
    }
24
}
25