CustomTypesRegistry::mapNameToType()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Types;
5
6
use GraphQL\Type\Definition\Type;
7
use GraphQL\Upload\UploadType;
8
9
/**
10
 * Keep track of all custom types (DateTimeType, UploadType...)
11
 */
12
class CustomTypesRegistry
13
{
14
    private static $uploadType;
15
16
    public static function getUploadType(): UploadType
17
    {
18
        if (self::$uploadType === null) {
19
            self::$uploadType = new UploadType();
20
        }
21
        return self::$uploadType;
22
    }
23
24
    public static function mapNameToType(string $name): ?Type
25
    {
26
        if ($name === 'Upload') {
27
            return self::getUploadType();
28
        }
29
30
        if ($name === 'DateTime') {
31
            return DateTimeType::getInstance();
32
        }
33
34
        return null;
35
    }
36
}
37