Completed
Pull Request — master (#153)
by Portey
04:20
created

SchemaConfig   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 85
ccs 20
cts 25
cp 0.8
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 7 2
A getQuery() 0 4 1
A setQuery() 0 6 1
A getMutation() 0 4 1
A getTypesList() 0 4 1
A getName() 0 4 1
A setMutation() 0 6 1
A getRules() 0 9 1
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 73
    public function __construct(array $configData, $contextObject = null, $finalClass = false)
27
    {
28 73
        $this->typesList = new SchemaTypesList();
29 73
        parent::__construct($configData, $contextObject, $finalClass);
30 73
    }
31
32
33
    public function getRules()
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 73
    protected function build()
44
    {
45 73
        parent::build();
46 73
        if (!empty($this->data['types'])) {
47
            $this->typesList->addTypes($this->data['types']);
48
        }
49 73
    }
50
51
52
    /**
53
     * @return AbstractObjectType
54
     */
55 73
    public function getQuery()
56
    {
57 73
        return $this->data['query'];
58
    }
59
60
    /**
61
     * @param $query AbstractObjectType
62
     *
63
     * @return SchemaConfig
64
     */
65 14
    public function setQuery($query)
66
    {
67 14
        $this->data['query'] = $query;
68
69 14
        return $this;
70
    }
71
72
    /**
73
     * @return ObjectType
74
     */
75 22
    public function getMutation()
76
    {
77 22
        return $this->get('mutation');
78
    }
79
80
    /**
81
     * @param $query AbstractObjectType
82
     *
83
     * @return SchemaConfig
84
     */
85 5
    public function setMutation($query)
86
    {
87 5
        $this->data['mutation'] = $query;
88
89 5
        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