Completed
Push — master ( b8b70e...552805 )
by Portey
03:44
created

ObjectTypeConfig   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 8
c 5
b 1
f 1
lcom 1
cbo 3
dl 10
loc 35
ccs 19
cts 20
cp 0.95
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRules() 10 10 1
B build() 0 17 7

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
* This file is a part of graphql-youshido project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 11/27/15 2:32 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Config\Object;
10
11
12
use Youshido\GraphQL\Type\AbstractType;
13
use Youshido\GraphQL\Type\Config\Config;
14
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
15
use Youshido\GraphQL\Type\Field\Field;
16
use Youshido\GraphQL\Type\Config\Traits\ArgumentsAwareTrait;
17
use Youshido\GraphQL\Type\Config\Traits\FieldsAwareTrait;
18
use Youshido\GraphQL\Type\Object\ObjectType;
19
use Youshido\GraphQL\Type\TypeMap;
20
21
class ObjectTypeConfig extends Config implements TypeConfigInterface
22
{
23
24
    use FieldsAwareTrait, ArgumentsAwareTrait;
25
26 8 View Code Duplication
    public function getRules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
27
    {
28
        return [
29 8
            'name'        => ['type' => TypeMap::TYPE_STRING, 'required' => true],
30 8
            'description' => ['type' => TypeMap::TYPE_STRING],
31 8
            'fields'      => ['type' => TypeMap::TYPE_ARRAY_OF_FIELDS],
32 8
            'args'        => ['type' => TypeMap::TYPE_ARRAY_OF_INPUTS],
33 8
            'resolve'     => ['type' => TypeMap::TYPE_FUNCTION],
34 8
        ];
35
    }
36
37 9
    protected function build()
38
    {
39 9
        $sourceFields = empty($this->data['fields']) ? [] : $this->data['fields'];
40 9
        foreach ($sourceFields as $fieldName => $fieldInfo) {
41 6
            if ($fieldInfo instanceof Field || $fieldInfo instanceof AbstractType) {
42 1
                $this->fields[$fieldName] = $fieldInfo;
43 1
                continue;
44
            };
45
46 5
            $this->addField($fieldName, $fieldInfo['type'], $fieldInfo);
47 9
        }
48
49 9
        $sourceArguments = empty($this->data['arguments']) ? [] : $this->data['arguments'];
50 9
        foreach ($sourceArguments as $argumentName => $argumentInfo) {
51
            $this->addArgument($argumentName, $argumentInfo['type'], $argumentInfo);
52 9
        }
53 9
    }
54
55
}