Completed
Push — master ( 75360a...120e4f )
by Portey
05:16
created

Schema   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 78.26%

Importance

Changes 14
Bugs 5 Features 3
Metric Value
wmc 10
c 14
b 5
f 3
lcom 1
cbo 4
dl 0
loc 53
ccs 18
cts 23
cp 0.7826
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 3 1
A addQuery() 0 4 1
A __construct() 0 14 3
A addMutation() 0 4 1
A getQueryType() 0 4 1
A getMutationType() 0 4 1
A getName() 0 6 2
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:40 PM
7
*/
8
9
namespace Youshido\GraphQL;
10
11
use Youshido\GraphQL\Type\Config\Schema\SchemaConfig;
12
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Object\InputObjectType;
15
use Youshido\GraphQL\Type\Object\ObjectType;
16
17
class Schema
18
{
19
20
    /** @var SchemaConfig */
21
    protected $config;
22
23 16
    public function __construct($config = [])
24
    {
25 16
        if (!array_key_exists('query', $config)) {
26 10
            $config['query'] = new ObjectType(['name' => $this->getName()]);
27
        }
28
29 16
        if (!array_key_exists('mutation', $config)) {
30 16
            $config['mutation'] = new InputObjectType(['name' => $this->getName()]);
31
        }
32
33 16
        $this->config = new SchemaConfig($config, $this);
34
35 15
        $this->build($this->config);
36 15
    }
37
38 9
    public function build(SchemaConfig $config)
39
    {
40 9
    }
41
42 14
    public function addQuery($name, AbstractObjectType $query, $config = [])
43
    {
44 14
        $this->getQueryType()->getConfig()->addField($name, $query, $config);
45 14
    }
46
47
    public function addMutation($name, AbstractObjectType $query, $config = [])
48
    {
49
        $this->getMutationType()->getConfig()->addField($name, $query, $config);
50
    }
51
52 14
    final public function getQueryType()
53
    {
54 14
        return $this->config->getQuery();
55
    }
56
57
    final public function getMutationType()
58
    {
59
        return $this->config->getMutation();
60
    }
61
62 15
    public function getName()
63
    {
64 15
        $defaultName = 'RootSchema';
65
66 15
        return $this->config ? $this->config->get('name', $defaultName) : $defaultName;
67
    }
68
69
}