CustomTypesRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUploadType() 0 6 2
A mapNameToType() 0 11 3
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