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

AbstractObjectType::parseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

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