Passed
Push — master ( 645e63...6cbe16 )
by Andrey
52s queued 14s
created

AbstractInputObjectType::getFields()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 12
c 0
b 0
f 0
nc 6
nop 0
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 7
rs 8.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Field\InputObjectFieldInterface;
8
use Andi\GraphQL\Definition\Type\InputObjectTypeInterface;
9
use Andi\GraphQL\Exception\CantResolveInputObjectFieldException;
10
use Andi\GraphQL\Field\FieldExtractorTrait;
11
use Andi\GraphQL\Field\InputObjectField;
12
use GraphQL\Type\Definition as Webonyx;
13
14
abstract class AbstractInputObjectType extends AbstractType implements InputObjectTypeInterface
15
{
16
    use FieldExtractorTrait;
17
18
    protected iterable $fields;
19
20 8
    public function getFields(): iterable
21
    {
22 8
        foreach ($this->fields as $name => $field) {
23 8
            if ($field instanceof Webonyx\InputObjectField || $field instanceof InputObjectFieldInterface) {
24 2
                yield $field;
25 6
            } elseif (is_string($field)) {
26 2
                yield new InputObjectField($name, $field);
27 4
            } elseif (is_array($field)) {
28 3
                if (is_string($name)) {
29 2
                    $field['name'] ??= $name;
30
                }
31
32 3
                yield $this->extract($field, InputObjectField::class);
33
            } else {
34 1
                throw new CantResolveInputObjectFieldException(
35 1
                    'Can\'t resolve InputObjectField configuration: unknown field configuration',
36 1
                );
37
            }
38
        }
39
    }
40
}
41