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

AbstractObjectType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 70%

Importance

Changes 7
Bugs 2 Features 3
Metric Value
wmc 8
c 7
b 2
f 3
lcom 1
cbo 3
dl 0
loc 51
ccs 14
cts 20
cp 0.7
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
resolve() 0 1 ?
build() 0 1 ?
A checkBuild() 0 7 2
A parseValue() 0 4 1
A serialize() 0 4 1
A getKind() 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 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
}