AbstractInputObjectType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B getFields() 0 16 7
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: unknown field configuration',
36 1
                );
37
            }
38
        }
39
    }
40
}
41