Completed
Push — master ( e1f92d...2bb6f9 )
by Antoine
21s queued 11s
created

TypesFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypes() 0 11 2
A __construct() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\GraphQl\Type;
15
16
use ApiPlatform\Core\GraphQl\Type\Definition\TypeInterface;
17
use Psr\Container\ContainerInterface;
18
19
/**
20
 * Get the registered services corresponding to GraphQL types.
21
 *
22
 * @experimental
23
 *
24
 * @author Alan Poulain <[email protected]>
25
 */
26
final class TypesFactory implements TypesFactoryInterface
27
{
28
    private $typeLocator;
29
    private $typeIds;
30
31
    /**
32
     * @param string[] $typeIds
33
     */
34
    public function __construct(ContainerInterface $typeLocator, array $typeIds)
35
    {
36
        $this->typeLocator = $typeLocator;
37
        $this->typeIds = $typeIds;
38
    }
39
40
    public function getTypes(): array
41
    {
42
        $types = [];
43
44
        foreach ($this->typeIds as $typeId) {
45
            /** @var TypeInterface $type */
46
            $type = $this->typeLocator->get($typeId);
47
            $types[$type->getName()] = $type;
48
        }
49
50
        return $types;
51
    }
52
}
53