Passed
Pull Request — main (#133)
by Tom
12:06
created

Metadata::getContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\GraphQL\Metadata;
6
7
use ApiSkeletons\Doctrine\GraphQL\AbstractContainer;
8
use ApiSkeletons\Doctrine\GraphQL\Type\Entity;
9
use GraphQL\Error\Error;
10
11
class Metadata extends AbstractContainer
12
{
13
    public function __construct(
14
        protected AbstractContainer $container,
15
        protected array|null $metadataConfig,
16
    ) {
17
    }
18
19
    public function getContainer(): AbstractContainer
20
    {
21
        return $this->container;
22
    }
23
24
    /** @throws Error */
25
    public function get(string $id): Entity
26
    {
27
        if ($this->has($id)) {
28
            return parent::get($id);
29
        }
30
31
        if (! isset($this->metadataConfig[$id])) {
32
            throw new Error(
33
                'Entity ' . $id . ' is not mapped in the metadata',
34
            );
35
        }
36
37
        return $this->build(Entity::class, $id, $this->metadataConfig[$id]);
38
    }
39
40
    public function getMetadataConfig(): array|null
41
    {
42
        return $this->metadataConfig;
43
    }
44
}
45