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

PostType::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 3
Ratio 15.79 %

Importance

Changes 12
Bugs 1 Features 1
Metric Value
c 12
b 1
f 1
dl 3
loc 19
rs 9.4285
cc 2
eloc 14
nc 1
nop 1
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