Completed
Push — master ( 9a8c05...020154 )
by Alexandr
02:48
created

Schema   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 4 Features 3
Metric Value
wmc 9
c 11
b 4
f 3
lcom 1
cbo 4
dl 0
loc 47
ccs 22
cts 22
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A build() 0 3 1
A addQuery() 0 4 1
A getQueryType() 0 4 1
A getMutationType() 0 4 1
A getName() 0 5 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 10
    public function __construct($config = [])
24
    {
25 10
        if (!array_key_exists('query', $config)) {
26 4
            $config['query'] = new ObjectType(['name' => $this->getName()]);
27 4
        }
28
29 10
        if (!array_key_exists('mutation', $config)) {
30 10
            $config['mutation'] = new InputObjectType(['name' => $this->getName()]);
31 10
        }
32
33 10
        $this->config = new SchemaConfig($config, $this);
34
35 9
        $this->build($this->getQueryType()->getConfig());
36 9
    }
37
38 8
    public function build(TypeConfigInterface $config)
39
    {
40 8
    }
41
42 7
    public function addQuery($name, AbstractObjectType $query, $config = [])
43
    {
44 7
        $this->getQueryType()->getConfig()->addField($name, $query, $config);
45 7
    }
46
47 9
    final public function getQueryType()
48
    {
49 9
        return $this->config->getQuery();
50
    }
51
52 1
    final public function getMutationType()
53
    {
54 1
        return $this->config->getMutation();
55
    }
56
57 9
    public function getName()
58
    {
59 9
        $defaultName = 'RootSchema';
60 9
        return $this->config ? $this->config->get('name', $defaultName) : $defaultName;
61
    }
62
63
}