| Total Complexity | 8 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class ASTDirector implements ASTDirectorInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var ASTBuilderInterface[] |
||
| 12 | */ |
||
| 13 | protected $builders; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * ASTBuilder constructor. |
||
| 17 | * |
||
| 18 | * @param ASTBuilderInterface[] $builders |
||
| 19 | */ |
||
| 20 | public function __construct($builders) |
||
| 21 | { |
||
| 22 | foreach ($builders as $builder) { |
||
| 23 | $builder->setDirector($this); |
||
| 24 | } |
||
| 25 | |||
| 26 | $this->builders = $builders; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @inheritdoc |
||
| 31 | */ |
||
| 32 | public function build(string $kind, LexerInterface $lexer, array $params = []): ?array |
||
| 33 | { |
||
| 34 | $builder = $this->getBuilder($kind); |
||
| 35 | |||
| 36 | if ($builder !== null) { |
||
| 37 | return $builder->build($lexer, $params); |
||
| 38 | } |
||
| 39 | |||
| 40 | throw new LanguageException(sprintf('AST of kind "%s" not supported.', $kind)); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param string $kind |
||
| 45 | * @return ASTBuilderInterface|null |
||
| 46 | */ |
||
| 47 | protected function getBuilder(string $kind): ?ASTBuilderInterface |
||
| 56 | } |
||
| 57 | } |
||
| 58 |