Completed
Pull Request — master (#51)
by Philipp
03:22
created

AbstractField::getDeprecationReason()   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

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Date: 13.05.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Field;
9
10
use Youshido\GraphQL\Config\Field\FieldConfig;
11
use Youshido\GraphQL\Config\Traits\ResolvableObjectTrait;
12
use Youshido\GraphQL\Type\AbstractType;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Traits\AutoNameTrait;
15
use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait;
16
use Youshido\GraphQL\Type\TypeFactory;
17
use Youshido\GraphQL\Type\TypeService;
18
19
abstract class AbstractField implements FieldInterface
20
{
21
22
    use FieldsArgumentsAwareObjectTrait;
23
    use ResolvableObjectTrait;
24
    use AutoNameTrait {
25
        getName as getAutoName;
26
    }
27
    protected $isFinal = false;
28
29
    private $resolveFunctionCache = null;
0 ignored issues
show
Unused Code introduced by
The property $resolveFunctionCache is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
    private $nameCache            = null;
31
32 70
    public function __construct(array $config = [])
33
    {
34 70
        if (empty($config['type'])) {
35 42
            $config['type'] = $this->getType();
36 42
            $config['name'] = $this->getName();
37 42
            if (empty($config['name'])) {
38 2
                $config['name'] =$this->getAutoName();
39 2
            }
40 42
        }
41
42 70
        if (TypeService::isScalarType($config['type'])) {
43 62
            $config['type'] = TypeFactory::getScalarType($config['type']);
44 62
        }
45 70
        $this->nameCache = isset($config['name']) ? $config['name'] : $this->getAutoName();
46
47 70
        $this->config = new FieldConfig($config, $this, $this->isFinal);
48 70
        $this->build($this->config);
49 70
    }
50
51
    /**
52
     * @return AbstractObjectType|AbstractType
53
     */
54
    abstract public function getType();
55
56 69
    public function build(FieldConfig $config)
57
    {
58 69
    }
59
60 1
    public function setType($type)
61
    {
62 1
        $this->getConfig()->set('type', $type);
63 1
    }
64
65 2
    public function getName()
66
    {
67 2
        return $this->nameCache;
68
    }
69
70 3
    public function isDeprecated()
71
    {
72 3
        return $this->getConfigValue('isDeprecated');
73
    }
74
75 3
    public function getDeprecationReason()
76
    {
77 3
        return $this->getConfigValue('deprecationReason');
78
    }
79
}
80