Completed
Push — master ( b8b70e...552805 )
by Portey
03:44
created

ObjectTypeConfig::build()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7.0223

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 17
ccs 12
cts 13
cp 0.9231
rs 8.2222
cc 7
eloc 10
nc 24
nop 0
crap 7.0223
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
}