Completed
Push — master ( f9f0ef...24a695 )
by Portey
05:15
created

AbstractObjectType   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 89.66%

Importance

Changes 9
Bugs 3 Features 3
Metric Value
wmc 9
c 9
b 3
f 3
lcom 1
cbo 3
dl 0
loc 57
ccs 26
cts 29
cp 0.8966
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
resolve() 0 1 ?
A __construct() 0 9 2
build() 0 1 ?
A checkBuild() 0 7 2
A parseValue() 0 4 1
A serialize() 0 4 1
A getKind() 0 4 1
A getInterfaces() 0 4 1
A isValidValue() 0 4 1
1
<?php
2
/*
3
* This file is a part of graphql-youshido project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 12/2/15 8:57 PM
7
*/
8
9
namespace Youshido\GraphQL\Type\Object;
10
11
12
use Youshido\GraphQL\Type\AbstractType;
13
use Youshido\GraphQL\Type\Config\Object\ObjectTypeConfig;
14
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
15
use Youshido\GraphQL\Type\TypeMap;
16
use Youshido\GraphQL\Validator\Exception\ResolveException;
17
18
abstract class AbstractObjectType extends AbstractType
19
{
20
21
    /**
22
     * ObjectType constructor.
23
     * @param $config
24
     */
25 23
    public function __construct($config = [])
26 1
    {
27 23
        if (empty($config)) {
28 21
            $config['name']       = $this->getName();
29 21
            $config['interfaces'] = $this->getInterfaces();
30 21
        }
31
32 23
        $this->config = new ObjectTypeConfig($config, $this);
33 23
    }
34
35
36
    abstract public function resolve($value = null, $args = []);
37
38
    abstract protected function build(TypeConfigInterface $config);
39
40 20
    public function checkBuild()
41 1
    {
42 20
        if (!$this->isBuild) {
43 20
            $this->isBuild = true;
44 20
            $this->build($this->config);
45 20
        }
46 20
    }
47
48
49 1
    public function parseValue($value)
50
    {
51
        return $value;
52 1
    }
53
54 1
    final public function serialize($value)
55 1
    {
56 1
        throw new ResolveException('You can not serialize object value directly');
57 1
    }
58
59 16
    public function getKind()
60 1
    {
61 16
        return TypeMap::KIND_OBJECT;
62
    }
63
64 21
    public function getInterfaces()
65
    {
66 21
        return [];
67
    }
68
69
    public function isValidValue($value)
70
    {
71
        return (get_class($value) == get_class($this));
72
    }
73
74
}