Types   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 24
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A __construct() 0 4 2
A set() 0 3 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2019 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Flange\GraphQL;
14
15
use GraphQL\Type\Definition\ObjectType;
16
17
/**
18
 * Types resolver for GraphQL schema.
19
 *
20
 * @author Divine Niiquaye Ibok <[email protected]>
21
 */
22
class Types
23
{
24
    /** @var array<string,ObjectType> */
25
    private array $types;
26
27
    public function __construct(array $types = [])
28
    {
29
        foreach ($types as $name => $type) {
30
            $this->set($name, $type);
31
        }
32
    }
33
34
    public function get($name)
35
    {
36
        if (!isset($this->types[$name])) {
37
            throw new \InvalidArgumentException(\sprintf('GraphQL object type for %s is not found.', $name));
38
        }
39
40
        return $this->types[$name];
41
    }
42
43
    public function set(string $name, ObjectType $type): void
44
    {
45
        $this->types[$name] = $type;
46
    }
47
}
48