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