|
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\Execution\ResolveInfo; |
|
12
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
|
13
|
|
|
use Youshido\GraphQL\Type\Traits\AutoNameTrait; |
|
14
|
|
|
use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait; |
|
15
|
|
|
use Youshido\GraphQL\Type\TypeFactory; |
|
16
|
|
|
use Youshido\GraphQL\Type\TypeService; |
|
17
|
|
|
|
|
18
|
|
|
abstract class AbstractField implements FieldInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
use FieldsArgumentsAwareObjectTrait, AutoNameTrait; |
|
22
|
|
|
|
|
23
|
|
|
protected $isFinal = false; |
|
24
|
|
|
|
|
25
|
|
|
protected $_resolve_cache = null; |
|
26
|
|
|
|
|
27
|
64 |
View Code Duplication |
public function __construct(array $config = []) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
64 |
|
if (empty($config['type'])) { |
|
30
|
30 |
|
$config['type'] = $this->getType(); |
|
31
|
30 |
|
$config['name'] = $this->getName(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
64 |
|
if (TypeService::isScalarType($config['type'])) { |
|
35
|
56 |
|
$config['type'] = TypeFactory::getScalarType($config['type']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
64 |
|
$this->config = new FieldConfig($config, $this, $this->isFinal); |
|
39
|
62 |
|
$this->build($this->config); |
|
40
|
62 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return AbstractObjectType |
|
44
|
|
|
*/ |
|
45
|
|
|
abstract public function getType(); |
|
46
|
|
|
|
|
47
|
61 |
|
public function build(FieldConfig $config) |
|
48
|
|
|
{ |
|
49
|
61 |
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function setType($type) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$this->getConfig()->set('type', $type); |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $value |
|
58
|
|
|
* @param array $args |
|
59
|
|
|
* @param ResolveInfo $info |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
*/ |
|
62
|
3 |
|
public function resolve($value, array $args, ResolveInfo $info) |
|
63
|
|
|
{ |
|
64
|
3 |
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
19 |
|
public function getResolveFunction() |
|
68
|
|
|
{ |
|
69
|
19 |
|
if ($this->_resolve_cache === null) { |
|
70
|
19 |
|
$this->_resolve_cache = $this->getConfig()->getResolveFunction(); |
|
71
|
19 |
|
if (!$this->_resolve_cache) { |
|
72
|
19 |
|
$this->_resolve_cache = false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
19 |
|
return $this->_resolve_cache; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
3 |
|
public function isDeprecated() |
|
79
|
|
|
{ |
|
80
|
3 |
|
return $this->getConfigValue('isDeprecated'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
3 |
|
public function getDeprecationReason() |
|
84
|
|
|
{ |
|
85
|
3 |
|
return $this->getConfigValue('deprecationReason'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.