Test Failed
Push — master ( 33bfdc...47f867 )
by Kirill
02:32
created

Frontend::buildFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 14
ccs 0
cts 5
cp 0
crap 12
rs 9.7998
c 0
b 0
f 0
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;
11
12
use Psr\Log\LoggerAwareInterface;
13
use Psr\Log\LoggerAwareTrait;
14
use Psr\Log\LoggerInterface;
15
use Railt\Io\Readable;
16
use Railt\Parser\Ast\RuleInterface;
17
use Railt\Parser\Exception\UnexpectedTokenException;
18
use Railt\Parser\Exception\UnrecognizedTokenException;
19
use Railt\SDL\Exception\SyntaxException;
20
use Railt\SDL\Frontend\Builder;
21
use Railt\SDL\Frontend\Context\ContextInterface;
22
use Railt\SDL\Frontend\Context\GlobalContext;
23
use Railt\SDL\Frontend\Parser;
24
use Railt\SDL\IR\DefinitionValueObject;
25
use Railt\SDL\IR\SymbolTable;
26
27
/**
28
 * Class Frontend
29
 */
30
class Frontend implements LoggerAwareInterface
31
{
32
    use LoggerAwareTrait;
33
34
    /**
35
     * @var Builder
36
     */
37
    private $builder;
38
39
    /**
40
     * Frontend constructor.
41
     */
42
    public function __construct()
43
    {
44
        $this->builder = new Builder();
45
    }
46
47
    /**
48
     * @param Readable $file
49
     * @return iterable
50
     * @throws SyntaxException
51
     * @throws \Railt\Io\Exception\ExternalFileException
52
     */
53
    public function load(Readable $file)
54
    {
55
        return $this->buildFile($file);
56
    }
57
58
    /**
59
     * @param Readable $readable
60
     * @return iterable
61
     * @throws SyntaxException
62
     * @throws \Railt\Io\Exception\ExternalFileException
63
     */
64
    public function buildFile(Readable $readable)
65
    {
66
        $process = $this->builder->buildFile($readable);
67
68
        /**
69
         * @var ContextInterface $context
70
         * @var mixed $result
71
         */
72
        foreach ($process as [$context, $result]) {
73
            if ($this->filter($context, $result)) {
0 ignored issues
show
Bug introduced by
The variable $context does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
74
                yield $result;
0 ignored issues
show
Bug introduced by
The variable $result does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
75
            }
76
        }
77
    }
78
79
    /**
80
     * @param ContextInterface $ctx
81
     * @param mixed $result
82
     * @return bool
83
     */
84
    private function filter(ContextInterface $ctx, $result): bool
0 ignored issues
show
Unused Code introduced by
The parameter $ctx is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        return $result !== null;
87
    }
88
89
    /**
90
     * @param LoggerInterface $logger
91
     * @return Frontend
92
     */
93
    public function setLogger(LoggerInterface $logger): self
94
    {
95
        $this->logger = $logger;
96
97
        return $this;
98
    }
99
}
100