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

SeldJsonLintJsonParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
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
use Seld\JsonLint\JsonParser;
8
use Seld\JsonLint\ParsingException;
9
10
final class SeldJsonLintJsonParser implements JsonParserInterface
11
{
12
    /**
13
     * @var JsonParser
14
     */
15
    private $parser;
16
17
    public function __construct()
18
    {
19
        $this->parser = new JsonParser();
20
    }
21
22
    /**
23
     * @param string $json
24
     * @return array|string|float|int|bool|null
25
     * @throws JsonParserException
26
     */
27
    public function parse(string $json)
28
    {
29
        try {
30
            return $this->parser->parse($json, JsonParser::PARSE_TO_ASSOC);
31
        } catch (ParsingException $e) {
32
            throw JsonParserException::createFromError($e->getMessage());
33
        }
34
    }
35
}
36