Completed
Push — master ( c1a156...8cadde )
by Kirill
08:14
created

SystemManager::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
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\Compiler;
11
12
use Psr\Log\LoggerAwareInterface;
13
use Psr\Log\LoggerAwareTrait;
14
use Railt\Parser\Ast\RuleInterface;
15
use Railt\Reflection\Contracts\Definition;
16
use Railt\SDL\Compiler\Process\Pipeline;
17
use Railt\SDL\Compiler\System;
18
use Railt\SDL\Compiler\System\SystemInterface;
19
20
/**
21
 * Class SystemManager
22
 */
23
class SystemManager implements SystemInterface, LoggerAwareInterface
24
{
25
    use LoggerAwareTrait;
26
27
    /**
28
     * @var SystemInterface[]
29
     */
30
    private const DEFAULT_SYSTEMS = [
31
        System\OffsetSystem::class,
32
        System\TypeHintSystem::class,
33
        System\DescriptionSystem::class,
34
        System\ImplementationSystem::class,
35
36
        System\Provider\FieldSystem::class,
37
        System\Provider\ArgumentSystem::class,
38
        System\Provider\DocumentSystem::class,
39
        System\Provider\DirectivesSystem::class,
40
        System\Provider\ArgumentInvocationSystem::class,
41
    ];
42
43
    /**
44
     * @var array|SystemInterface[]
45
     */
46
    private $systems = [];
47
48
    /**
49
     * SystemManager constructor.
50
     * @param Builder $process
51
     * @param Pipeline $pipeline
52
     */
53 119
    public function __construct(Builder $process, Pipeline $pipeline)
54
    {
55 119
        $this->boot($process, $pipeline);
56 119
    }
57
58
    /**
59
     * @param Builder $process
60
     * @param Pipeline $pipeline
61
     * @return void
62
     */
63 119
    private function boot(Builder $process, Pipeline $pipeline): void
64
    {
65 119
        foreach (self::DEFAULT_SYSTEMS as $system) {
66 119
            $this->systems[] = new $system($process, $pipeline);
67
        }
68 119
    }
69
70
    /**
71
     * @param Definition $def
72
     * @param RuleInterface $ast
73
     */
74 119
    public function resolve(Definition $def, RuleInterface $ast): void
75
    {
76 119
        foreach ($this->systems as $system) {
77 119
            if ($this->logger) {
78
                $message = 'Apply system %s for %s (%s:%d)';
79
                $this->logger->debug(\sprintf($message, \get_class($system),
80
                    $def, $def->getFile()->getPathname(), $def->getLine()));
81
            }
82
83 119
            $system->resolve($def, $ast);
84
        }
85 119
    }
86
}
87