Passed
Pull Request — master (#900)
by Michael
02:50
created

Parser::parse()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 3
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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 427
    public function __construct()
36
    {
37 427
        $this->parser = new InnerParser();
38 427
        $this->visitor = new TypeVisitor();
39 427
    }
40
41 304
    public function parse(string $type) : array
42
    {
43
        try {
44 304
            $ast = $this->parser->parse($type, 'type');
45
46 298
            return $this->visitor->visit($ast);
47 6
        } catch (Exception $e) {
48 6
            throw new SyntaxError($e->getMessage(), 0, $e);
49
        }
50
    }
51
}
52