1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is a part of graphql-youshido project. |
4
|
|
|
* |
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
6
|
|
|
* created: 11/27/15 2:32 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Type\Config\Object; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Type\AbstractType; |
13
|
|
|
use Youshido\GraphQL\Type\Config\Config; |
14
|
|
|
use Youshido\GraphQL\Type\Config\TypeConfigInterface; |
15
|
|
|
use Youshido\GraphQL\Type\Field\Field; |
16
|
|
|
use Youshido\GraphQL\Type\Config\Traits\ArgumentsAwareTrait; |
17
|
|
|
use Youshido\GraphQL\Type\Config\Traits\FieldsAwareTrait; |
18
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
19
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
20
|
|
|
|
21
|
|
|
class ObjectTypeConfig extends Config implements TypeConfigInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
use FieldsAwareTrait, ArgumentsAwareTrait; |
25
|
|
|
|
26
|
8 |
View Code Duplication |
public function getRules() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
8 |
|
'name' => ['type' => TypeMap::TYPE_STRING, 'required' => true], |
30
|
8 |
|
'description' => ['type' => TypeMap::TYPE_STRING], |
31
|
8 |
|
'fields' => ['type' => TypeMap::TYPE_ARRAY_OF_FIELDS], |
32
|
8 |
|
'args' => ['type' => TypeMap::TYPE_ARRAY_OF_INPUTS], |
33
|
8 |
|
'resolve' => ['type' => TypeMap::TYPE_FUNCTION], |
34
|
8 |
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
9 |
|
protected function build() |
38
|
|
|
{ |
39
|
9 |
|
$sourceFields = empty($this->data['fields']) ? [] : $this->data['fields']; |
40
|
9 |
|
foreach ($sourceFields as $fieldName => $fieldInfo) { |
41
|
6 |
|
if ($fieldInfo instanceof Field || $fieldInfo instanceof AbstractType) { |
42
|
1 |
|
$this->fields[$fieldName] = $fieldInfo; |
43
|
1 |
|
continue; |
44
|
|
|
}; |
45
|
|
|
|
46
|
5 |
|
$this->addField($fieldName, $fieldInfo['type'], $fieldInfo); |
47
|
9 |
|
} |
48
|
|
|
|
49
|
9 |
|
$sourceArguments = empty($this->data['arguments']) ? [] : $this->data['arguments']; |
50
|
9 |
|
foreach ($sourceArguments as $argumentName => $argumentInfo) { |
51
|
|
|
$this->addArgument($argumentName, $argumentInfo['type'], $argumentInfo); |
52
|
9 |
|
} |
53
|
9 |
|
} |
54
|
|
|
|
55
|
|
|
} |
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.