CannotMapTypeException   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 51
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A mustBeOutputType() 0 3 1
A wrapWithReturnInfo() 0 8 1
A createForName() 0 3 1
A createForInputType() 0 3 1
A wrapWithParamInfo() 0 9 1
A createForExtendType() 0 3 1
A createForExtendName() 0 3 1
A createForType() 0 3 1
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Mappers;
5
6
7
use GraphQL\Type\Definition\ObjectType;
8
use ReflectionMethod;
9
10
class CannotMapTypeException extends \Exception implements CannotMapTypeExceptionInterface
11
{
12
    public static function createForType(string $className): self
13
    {
14
        return new self('cannot map class "'.$className.'" to a known GraphQL type. Check your TypeMapper configuration.');
15
    }
16
17
    public static function createForInputType(string $className): self
18
    {
19
        return new self('cannot map class "'.$className.'" to a known GraphQL input type. Check your TypeMapper configuration.');
20
    }
21
22
    public static function createForName(string $name): self
23
    {
24
        return new self('cannot find GraphQL type "'.$name.'". Check your TypeMapper configuration.');
25
    }
26
27
    public static function wrapWithParamInfo(CannotMapTypeExceptionInterface $previous, \ReflectionParameter $parameter): self
28
    {
29
        $message = sprintf('For parameter $%s, in %s::%s, %s',
30
            $parameter->getName(),
31
            $parameter->getDeclaringClass()->getName(),
32
            $parameter->getDeclaringFunction()->getName(),
33
            $previous->getMessage());
34
35
        return new self($message, 0, $previous);
36
    }
37
38
    public static function wrapWithReturnInfo(CannotMapTypeExceptionInterface $previous, ReflectionMethod $method): self
39
    {
40
        $message = sprintf('For return type of %s::%s, %s',
41
            $method->getDeclaringClass()->getName(),
42
            $method->getName(),
43
            $previous->getMessage());
44
45
        return new self($message, 0, $previous);
46
    }
47
48
    public static function mustBeOutputType($subTypeName): self
49
    {
50
        return new self('type "'.$subTypeName.'" must be an output type.');
51
    }
52
53
    public static function createForExtendType(string $className, ObjectType $type): self
54
    {
55
        return new self('cannot extend GraphQL type "'.$type->name.'" mapped by class "'.$className.'". Check your TypeMapper configuration.');
56
    }
57
58
    public static function createForExtendName(string $name, ObjectType $type): self
59
    {
60
        return new self('cannot extend GraphQL type "'.$type->name.'" with type "'.$name.'". Check your TypeMapper configuration.');
61
    }
62
}
63