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

Metadata   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 32
rs 10
c 4
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadataConfig() 0 3 1
A __construct() 0 4 1
A get() 0 13 3
A getContainer() 0 3 1
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