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

Schema::buildTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 4
Bugs 2 Features 1
Metric Value
c 4
b 2
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 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: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
}