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

CannotMapTypeException::wrapWithParamInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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