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

SeldJsonLintJsonParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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