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

PostType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 14
Bugs 1 Features 2
Metric Value
wmc 5
c 14
b 1
f 2
lcom 0
cbo 10
dl 3
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 3 19 2
A getInterfaces() 0 4 1
A resolve() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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