Completed
Push — master ( f8702a...461e07 )
by Alexandr
04:08
created

PostType::getInterfaces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * PostType.php
4
 */
5
6
namespace Examples\Blog\Schema;
7
8
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
9
use Youshido\GraphQL\Type\NonNullType;
10
use Youshido\GraphQL\Type\Object\AbstractObjectType;
11
use Youshido\GraphQL\Type\Scalar\BooleanType;
12
use Youshido\GraphQL\Type\Scalar\IntType;
13
use Youshido\GraphQL\Type\Scalar\StringType;
14
use Youshido\GraphQL\Type\Traits\AutoNameTrait;
15
16
class PostType extends AbstractObjectType
17
{
18
    public function build(TypeConfigInterface $config)
19
    {
20
        $config
21
            ->addField('oldTitle', new NonNullType(new StringType()), [
22
                'description'       => 'This field contains a post title',
23
                'isDeprecated'      => true,
24
                'deprecationReason' => 'field title is now deprecated',
25
                'args'              => [
26
                    'truncated' => new BooleanType()
27
                ],
28 View Code Duplication
                'resolve'           => function ($value, $args) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
                    return (!empty($args['truncated'])) ? explode(' ', $value)[0] . '...' : $value;
30
                }
31
            ])
32
            ->addField('title', new NonNullType(new StringType()))
33
            ->addField('status', new PostStatus())
34
            ->addField('summary', new StringType())
35
            ->addField('likeCount', new IntType());
36
    }
37
38
    public function getInterfaces()
39
    {
40
        return [new ContentBlockInterface()];
41
    }
42
43
    public function resolve($value = null, $args = [], $type = null)
44
    {
45
        return DataProvider::getPost(empty($args['id']) ? 1 : $args['id']);
46
    }
47
48
}
49