Completed
Push — master ( 7f89eb...d01340 )
by Portey
05:11
created

AbstractObjectType::checkBuild()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4286
nc 2
cc 2
eloc 4
nop 0
crap 2
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 12
    public function __construct($config = [])
26
    {
27 12
        if (empty($config)) {
28 10
            $config['name'] = $this->getName();
29 10
        }
30
31 12
        $this->config = new ObjectTypeConfig($config, $this);
32 12
    }
33
34
35
    abstract public function resolve($value = null, $args = []);
36
37
    abstract protected function build(TypeConfigInterface $config);
38
39 12
    public function checkBuild()
40
    {
41 12
        if (!$this->isBuild) {
42 12
            $this->isBuild = true;
43 12
            $this->build($this->config);
44 12
        }
45 12
    }
46
47
    public function parseValue($value)
48
    {
49
        return $value;
50
    }
51
52
    final public function serialize($value)
53
    {
54
        throw new ResolveException('You can not serialize object value directly');
55
    }
56
57 7
    public function getKind()
58
    {
59 7
        return TypeMap::KIND_OBJECT;
60
    }
61
62
63
    public function isValidValue($value)
64
    {
65
        return (get_class($value) == get_class($this));
66
    }
67
68
}