| Total Complexity | 9 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class NodeDirector implements NodeDirectorInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var NodeBuilderInterface[] |
||
| 12 | */ |
||
| 13 | protected $builders; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * NodeBuilder constructor. |
||
| 17 | * |
||
| 18 | * @param NodeBuilderInterface[] $builders |
||
| 19 | */ |
||
| 20 | public function __construct($builders) |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param array $ast |
||
| 31 | * @return NodeInterface |
||
| 32 | * @throws LanguageException |
||
| 33 | */ |
||
| 34 | public function build(array $ast): NodeInterface |
||
| 35 | { |
||
| 36 | if (!isset($ast['kind'])) { |
||
| 37 | throw new LanguageException(sprintf('Nodes must specify a kind, got %s', json_encode($ast))); |
||
| 38 | } |
||
| 39 | |||
| 40 | $builder = $this->getBuilder($ast['kind']); |
||
| 41 | |||
| 42 | if ($builder !== null) { |
||
| 43 | return $builder->build($ast); |
||
| 44 | } |
||
| 45 | |||
| 46 | throw new LanguageException(sprintf('Node of kind "%s" not supported.', $ast['kind'])); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $kind |
||
| 51 | * @return NodeBuilderInterface|null |
||
| 52 | */ |
||
| 53 | protected function getBuilder(string $kind): ?NodeBuilderInterface |
||
| 62 | } |
||
| 63 | } |
||
| 64 |