Passed
Push — master ( c180c0...233e00 )
by Divine Niiquaye
12:12
created

Types::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\GraphQL;
19
20
use GraphQL\Type\Definition\ObjectType;
0 ignored issues
show
Bug introduced by
The type GraphQL\Type\Definition\ObjectType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
/**
23
 * Types resolver for GraphQL schema.
24
 *
25
 * @author Divine Niiquaye Ibok <[email protected]>
26
 */
27
class Types
28
{
29
    /** @var array<string,ObjectType> */
30
    private array $types;
31
32
    public function __construct(array $types = [])
33
    {
34
        foreach ($types as $name => $type) {
35
            $this->set($name, $type);
36
        }
37
    }
38
39
    public function get($name)
40
    {
41
        if (!isset($this->types[$name])) {
42
            throw new \InvalidArgumentException(\sprintf('GraphQL object type for %s is not found.', $name));
43
        }
44
45
        return $this->types[$name];
46
    }
47
48
    public function set(string $name, ObjectType $type): void
49
    {
50
        $this->types[$name] = $type;
51
    }
52
}
53