Completed
Push — master ( 3977d8...7ec8b3 )
by David
15s queued 11s
created

CannotMapTypeException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

6 Methods

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