Completed
Push — master ( e75494...e13501 )
by Alexandr
03:05
created

AbstractSchema   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 60
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
build() 0 1 ?
A addQueryField() 0 4 1
A addMutationField() 0 4 1
A getQueryType() 0 4 1
A getMutationType() 0 4 1
A getTypesList() 0 4 1
A getName() 0 6 2
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/5/16 9:24 PM
7
*/
8
9
namespace Youshido\GraphQL\Schema;
10
11
12
use Youshido\GraphQL\Config\Schema\SchemaConfig;
13
use Youshido\GraphQL\Type\Object\ObjectType;
14
use Youshido\GraphQL\Type\SchemaTypesList;
15
use Youshido\GraphQL\Type\TypeInterface;
16
17
abstract class AbstractSchema
18
{
19
20
    /** @var SchemaConfig */
21
    protected $config;
22
23 49
    public function __construct($config = [])
24
    {
25 49
        if (!array_key_exists('query', $config)) {
26 32
            $config['query'] = new InternalSchemaQueryObject(['name' => $this->getName() . 'Query']);
27
        }
28 49
        if (!array_key_exists('mutation', $config)) {
29 47
            $config['mutation'] = new InternalSchemaMutationObject(['name' => $this->getName() . 'Mutation']);
30
        }
31 49
        if (!array_key_exists('types', $config)) {
32 49
          $config['types'] = [];
33
        }
34
35 49
        $this->config = new SchemaConfig($config, $this);
36
37 49
        $this->build($this->config);
38 49
    }
39
40
    abstract public function build(SchemaConfig $config);
41
42 41
    public function addQueryField($field, $fieldInfo = null)
43
    {
44 41
        $this->getQueryType()->addField($field, $fieldInfo);
45 41
    }
46
47 2
    public function addMutationField($field, $fieldInfo = null)
48
    {
49 2
        $this->getMutationType()->addField($field, $fieldInfo);
50 2
    }
51
52 49
    final public function getQueryType()
53
    {
54 49
        return $this->config->getQuery();
55
    }
56
57 31
    final public function getMutationType()
58
    {
59 31
        return $this->config->getMutation();
60
    }
61
62
    /**
63
     * @return SchemaTypesList
64
     */
65 6
    public function getTypesList()
66
    {
67 6
        return $this->config->getTypesList();
68
    }
69
70 36
    public function getName()
71
    {
72 36
        $defaultName = 'RootSchema';
73
74 36
        return $this->config ? $this->config->get('name', $defaultName) : $defaultName;
75
    }
76
}
77