Completed
Push — master ( 121747...dcf58a )
by Alexandr
02:37
created

SchemaConfig   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 99
Duplicated Lines 10.1 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 10
loc 99
ccs 24
cts 30
cp 0.8
rs 10
c 0
b 0
f 0

10 Methods

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