Test Failed
Push — master ( 08b170...e6bc2a )
by Kirill
02:02
created

Frontend::exec()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
use Railt\AST\Parser;
13
use Railt\Io\Exception\ExternalFileException;
14
use Railt\Io\Readable;
15
use Railt\Parser\Ast\RuleInterface;
16
use Railt\Parser\ParserInterface;
17
use Railt\SDL\Exception\InternalErrorException;
18
use Railt\SDL\Exception\SyntaxException;
19
20
/**
21
 * Class Frontend
22
 */
23
class Frontend
24
{
25
    /**
26
     * @var ParserInterface
27
     */
28
    private $parser;
29
30
    /**
31
     * Frontend constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->parser = new Parser();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Railt\AST\Parser() of type object<Railt\AST\Parser> is incompatible with the declared type object<Railt\Parser\ParserInterface> of property $parser.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
    }
37
38
    /**
39
     * @param Readable $schema
40
     * @return RuleInterface
41
     * @throws SyntaxException
42
     * @throws InternalErrorException
43
     */
44
    public function exec(Readable $schema): RuleInterface
45
    {
46
        try {
47
            return $this->parser->parse($schema);
48
49
        } catch (ExternalFileException $e) {
50
            $exception = new SyntaxException($e->getMessage());
51
            $exception->throwsIn($schema, $e->getLine(), $e->getColumn());
52
53
            throw $exception;
54
55
        } catch (\Throwable $e) {
56
            throw new InternalErrorException($e->getMessage());
57
        }
58
    }
59
}
60