Completed
Pull Request — master (#204)
by Ryan
11:34
created

AbstractField::__construct()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 6
nop 1
crap 4
1
<?php
2
/**
3
 * Copyright (c) 2015–2018 Alexandr Viniychuk <http://youshido.com>.
4
 * Copyright (c) 2015–2018 Portey Vasil <https://github.com/portey>.
5
 * Copyright (c) 2018 Ryan Parman <https://github.com/skyzyx>.
6
 * Copyright (c) 2018 Ashley Hutson <https://github.com/asheliahut>.
7
 * Copyright (c) 2015–2018 Contributors.
8
 *
9
 * http://opensource.org/licenses/MIT
10
 */
11
12
declare(strict_types=1);
13
/**
14
 * Date: 13.05.16.
15
 */
16
17
namespace Youshido\GraphQL\Field;
18
19
use Youshido\GraphQL\Config\Field\FieldConfig;
20
use Youshido\GraphQL\Config\Traits\ResolvableObjectTrait;
21
use Youshido\GraphQL\Type\AbstractType;
22
use Youshido\GraphQL\Type\Object\AbstractObjectType;
23
use Youshido\GraphQL\Type\Traits\AutoNameTrait;
24
use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait;
25
use Youshido\GraphQL\Type\TypeFactory;
26
use Youshido\GraphQL\Type\TypeService;
27
28
abstract class AbstractField implements FieldInterface
29
{
30
    use FieldsArgumentsAwareObjectTrait;
31 102
    use ResolvableObjectTrait;
32
    use AutoNameTrait {
33 102
        getName as getAutoName;
34 75
    }
35 75
36 75
    protected $isFinal = false;
37 2
38
    private $nameCache;
39
40
    public function __construct(array $config = [])
41 102
    {
42 94
        if (empty($config['type'])) {
43
            $config['type'] = $this->getType();
44 102
            $config['name'] = $this->getName();
45
46 102
            if (empty($config['name'])) {
47 102
                $config['name'] = $this->getAutoName();
48 102
            }
49
        }
50
51
        if (TypeService::isScalarType($config['type'])) {
52
            $config['type'] = TypeFactory::getScalarType($config['type']);
53
        }
54
        $this->nameCache = $config['name'] ?? $this->getAutoName();
55 101
56
        $this->config = new FieldConfig($config, $this, $this->isFinal);
57 101
        $this->build($this->config);
58
    }
59 1
60
    /**
61 1
     * @return AbstractObjectType|AbstractType
62 1
     */
63
    abstract public function getType();
64 2
65
    public function build(FieldConfig $config): void
66 2
    {
67
    }
68
69 5
    public function setType($type): void
70
    {
71 5
        $this->getConfig()->set('type', $type);
72
    }
73
74 5
    public function getName()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
75
    {
76 5
        return $this->nameCache;
77
    }
78
79
    public function isDeprecated()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
80
    {
81
        return $this->getConfigValue('isDeprecated', false);
82
    }
83
84
    public function getDeprecationReason()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
85
    {
86
        return $this->getConfigValue('deprecationReason');
87
    }
88
}
89