AnyScalarTypeMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toGraphQLInputType() 0 7 2
A toGraphQLOutputType() 0 7 2
A mapNameToType() 0 6 2
1
<?php
2
3
4
namespace TheCodingMachine\GraphQLite\Types\AnyScalar;
5
6
7
use GraphQL\Type\Definition\InputType;
8
use GraphQL\Type\Definition\NamedType;
9
use GraphQL\Type\Definition\OutputType;
10
use phpDocumentor\Reflection\DocBlock;
11
use phpDocumentor\Reflection\Type;
12
use phpDocumentor\Reflection\Types\Scalar;
13
use ReflectionMethod;
14
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperInterface;
15
16
class AnyScalarTypeMapper implements RootTypeMapperInterface
17
{
18
19
    public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod $refMethod, DocBlock $docBlockObj): ?OutputType
20
    {
21
        if ($type instanceof Scalar) {
22
            // AnyScalarType is a class implementing the Webonyx ScalarType type.
23
            return AnyScalarType::getInstance();
24
        }
25
        return null;
26
    }
27
28
    public function toGraphQLInputType(Type $type, ?InputType $subType, string $argumentName, ReflectionMethod $refMethod, DocBlock $docBlockObj): ?InputType
29
    {
30
        if ($type instanceof Scalar) {
31
            // AnyScalarType is a class implementing the Webonyx ScalarType type.
32
            return AnyScalarType::getInstance();
33
        }
34
        return null;
35
    }
36
37
    /**
38
     * Returns a GraphQL type by name.
39
     * If this root type mapper can return this type in "toGraphQLOutputType" or "toGraphQLInputType", it should
40
     * also map these types by name in the "mapNameToType" method.
41
     *
42
     * @param string $typeName The name of the GraphQL type
43
     * @return NamedType|null
44
     */
45
    public function mapNameToType(string $typeName): ?NamedType
46
    {
47
        if ($typeName === AnyScalarType::NAME) {
48
            return AnyScalarType::getInstance();
49
        }
50
        return null;
51
    }
52
}
53