Passed
Pull Request — master (#900)
by Michael
03:06
created

Parser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 8 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace JMS\Serializer\Type;
22
23
use Hoa\Exception\Exception;
24
use Hoa\Visitor\Visit;
25
use JMS\Serializer\Type\Exception\SyntaxError;
26
27
final class Parser implements ParserInterface
28
{
29
    /** @var InnerParser */
30
    private $parser;
31
32
    /** @var Visit */
33
    private $visitor;
34
35 404
    public function __construct()
36
    {
37 404
        $this->parser = new InnerParser();
38 404
        $this->visitor = new TypeVisitor();
39 404
    }
40
41 284
    public function parse(string $type) : array
42
    {
43
        try {
44 284
            $ast = $this->parser->parse($type, 'type');
45
46 279
            return $this->visitor->visit($ast);
47 5
        } catch (Exception $e) {
48 5
            throw new SyntaxError($e->getMessage(), 0, $e);
49
        }
50
    }
51
}
52