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

SeldJsonLintJsonParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 26
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 8 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