Completed
Pull Request — master (#77)
by Sebastian
03:02
created

SchemaConfig   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 10.59 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 9
loc 85
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getRules() 9 9 1
A build() 0 7 2
A getQuery() 0 4 1
A setQuery() 0 6 1
A getMutation() 0 4 1
A setMutation() 0 6 1
A getName() 0 4 1
A getTypesList() 0 4 1

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/28/15 3:53 PM
7
*/
8
9
namespace Youshido\GraphQL\Config\Schema;
10
11
12
use Youshido\GraphQL\Config\AbstractConfig;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Object\ObjectType;
15
use Youshido\GraphQL\Type\SchemaTypesList;
16
use Youshido\GraphQL\Type\TypeService;
17
18
class SchemaConfig extends AbstractConfig
19
{
20
21
    /**
22
     * @var SchemaTypesList
23
     */
24
    private $typesList;
25
26 49
    public function __construct(array $configData, $contextObject = null, $finalClass = false)
27
    {
28 49
        $this->typesList = new SchemaTypesList();
29 49
        parent::__construct($configData, $contextObject, $finalClass);
30 49
    }
31
32
33 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...
34
    {
35
        return [
36
            'query'    => ['type' => TypeService::TYPE_OBJECT_TYPE, 'required' => true],
37
            'mutation' => ['type' => TypeService::TYPE_OBJECT_TYPE],
38
            'types'    => ['type' => TypeService::TYPE_ARRAY],
39
            'name'     => ['type' => TypeService::TYPE_STRING],
40
        ];
41
    }
42
43 49
    protected function build()
44
    {
45 49
        parent::build();
46 49
        if (!empty($this->data['types'])) {
47
            $this->typesList->addTypes($this->data['types']);
48
        }
49 49
    }
50
51
52
    /**
53
     * @return AbstractObjectType
54
     */
55 49
    public function getQuery()
56
    {
57 49
        return $this->data['query'];
58
    }
59
60
    /**
61
     * @param $query AbstractObjectType
62
     *
63
     * @return SchemaConfig
64
     */
65 7
    public function setQuery($query)
66
    {
67 7
        $this->data['query'] = $query;
68
69 7
        return $this;
70
    }
71
72
    /**
73
     * @return ObjectType
74
     */
75 41
    public function getMutation()
76
    {
77 41
        return $this->get('mutation');
78
    }
79
80
    /**
81
     * @param $query AbstractObjectType
82
     *
83
     * @return SchemaConfig
84
     */
85
    public function setMutation($query)
86
    {
87
        $this->data['mutation'] = $query;
88
89
        return $this;
90
    }
91
92
    public function getName()
93
    {
94
        return $this->get('name', 'RootSchema');
95
    }
96
97 6
    public function getTypesList()
98
    {
99 6
        return $this->typesList;
100
    }
101
102
}
103