IdArgumentGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 12 3
1
<?php
2
3
namespace DeInternetJongens\LighthouseUtils\Generators\Arguments;
4
5
use GraphQL\Type\Definition\IDType;
6
use GraphQL\Type\Definition\Type;
7
8
class IdArgumentGenerator
9
{
10
    /**
11
     * Generates a GraphQL ID argument
12
     * More information:
13
     * https://lighthouse-php.netlify.com/docs/schema.html#input-types
14
     *
15
     * @param Type[] $typeFields
16
     * @return array
17
     */
18
    public static function generate(array $typeFields): array
19
    {
20
        foreach ($typeFields as $fieldName => $field) {
21
            $className = get_class($field);
22
            if ($className === IDType::class) {
23
                return [
24
                    sprintf('%s: %s!', $fieldName, $field->name)
25
                ];
26
            };
27
        }
28
29
        return [];
30
    }
31
}
32