TypeFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 50
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getScalarTypesNames() 0 14 1
B getScalarType() 0 21 6
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/11/16 9:19 PM
7
*/
8
9
namespace Youshido\GraphQL\Type;
10
11
12
use Youshido\GraphQL\Exception\ConfigurationException;
13
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
14
15
class TypeFactory
16
{
17
    private static $objectsHash = [];
18
19
    /**
20
     * @param string $type
21
     *
22
     * @throws ConfigurationException
23
     * @return AbstractScalarType
24
     */
25 119
    public static function getScalarType($type)
26
    {
27 119
        if (TypeService::isScalarType($type)) {
28 119
            if (is_object($type)) {
29 104
                return $type;
30
            }
31 97
            if (empty(self::$objectsHash[$type])) {
32 5
                $name = ucfirst($type);
33
34 5
                $name = $name == 'Datetime' ? 'DateTime' : $name;
35 5
                $name = $name == 'Datetimetz' ? 'DateTimeTz' : $name;
36
37 5
                $className                = 'Youshido\GraphQL\Type\Scalar\\' . $name . 'Type';
38 5
                self::$objectsHash[$type] = new $className();
39 5
            }
40
41 97
            return self::$objectsHash[$type];
42
        } else {
43 1
            throw new ConfigurationException('Configuration problem with type ' . $type);
44
        }
45
    }
46
47
    /**
48
     * @return string[]
49
     */
50 101
    public static function getScalarTypesNames()
51
    {
52
        return [
53 101
            TypeMap::TYPE_INT,
54 101
            TypeMap::TYPE_FLOAT,
55 101
            TypeMap::TYPE_STRING,
56 101
            TypeMap::TYPE_BOOLEAN,
57 101
            TypeMap::TYPE_ID,
58 101
            TypeMap::TYPE_DATETIME,
59 101
            TypeMap::TYPE_DATE,
60 101
            TypeMap::TYPE_TIMESTAMP,
61 101
            TypeMap::TYPE_DATETIMETZ,
62 101
        ];
63
    }
64
}
65