GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e7bef7...3cccd4 )
by Šimon
03:07
created

ImageType::resolveUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
namespace GraphQL\Examples\Blog\Type;
3
4
use GraphQL\Examples\Blog\AppContext;
5
use GraphQL\Examples\Blog\Data\Image;
6
use GraphQL\Examples\Blog\Types;
7
use GraphQL\Type\Definition\EnumType;
8
use GraphQL\Type\Definition\ObjectType;
9
10
class ImageType extends ObjectType
11
{
12
    public function __construct()
13
    {
14
        $config = [
15
            'name' => 'ImageType',
16
            'fields' => [
17
                'id' => Types::id(),
18
                'type' => new EnumType([
19
                    'name' => 'ImageTypeEnum',
20
                    'values' => [
21
                        'USERPIC' => Image::TYPE_USERPIC
22
                    ]
23
                ]),
24
                'size' => Types::imageSizeEnum(),
25
                'width' => Types::int(),
26
                'height' => Types::int(),
27
                'url' => [
28
                    'type' => Types::url(),
29
                    'resolve' => [$this, 'resolveUrl']
30
                ],
31
32
                // Just for the sake of example
33
                'fieldWithError' => [
34
                    'type' => Types::string(),
35
                    'resolve' => function() {
36
                        throw new \Exception("Field with exception");
37
                    }
38
                ],
39
                'nonNullFieldWithError' => [
40
                    'type' => Types::nonNull(Types::string()),
41
                    'resolve' => function() {
42
                        throw new \Exception("Non-null field with exception");
43
                    }
44
                ]
45
            ]
46
        ];
47
48
        parent::__construct($config);
49
    }
50
51
    public function resolveUrl(Image $value, $args, AppContext $context)
52
    {
53
        switch ($value->type) {
54
            case Image::TYPE_USERPIC:
55
                $path = "/images/user/{$value->id}-{$value->size}.jpg";
56
                break;
57
            default:
58
                throw new \UnexpectedValueException("Unexpected image type: " . $value->type);
59
        }
60
        return $context->rootUrl . $path;
61
    }
62
}
63