Completed
Push — master ( 951598...dccc62 )
by David
03:06 queued 44s
created

CannotMapTypeException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A wrapWithReturnInfo() 0 8 1
A createForInputType() 0 3 1
A wrapWithParamInfo() 0 9 1
A createForType() 0 3 1
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Mappers;
5
6
7
use ReflectionMethod;
8
9
class CannotMapTypeException extends \Exception
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 wrapWithParamInfo(self $previous, \ReflectionParameter $parameter): self
22
    {
23
        $message = sprintf('For parameter $%s, in %s::%s, %s',
24
            $parameter->getName(),
25
            $parameter->getDeclaringClass()->getName(),
26
            $parameter->getDeclaringFunction()->getName(),
27
            $previous->getMessage());
28
29
        return new self($message, 0, $previous);
30
    }
31
32
    public static function wrapWithReturnInfo(self $previous, ReflectionMethod $method): self
33
    {
34
        $message = sprintf('For return type of %s::%s, %s',
35
            $method->getDeclaringClass()->getName(),
36
            $method->getName(),
37
            $previous->getMessage());
38
39
        return new self($message, 0, $previous);
40
    }
41
}
42