1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Andi\GraphQL\Field; |
||
6 | |||
7 | use GraphQL\Type\Definition as Webonyx; |
||
8 | |||
9 | trait FieldExtractorTrait |
||
10 | { |
||
11 | /** |
||
12 | * @param array{ |
||
13 | * name: string, |
||
14 | * type: Webonyx\Type|string, |
||
15 | * mode: int, |
||
16 | * description: string, |
||
17 | * deprecationReason: string, |
||
18 | * defaultValue: mixed |
||
19 | * } $config |
||
20 | * @param class-string $class |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
21 | * |
||
22 | * @return mixed |
||
23 | */ |
||
24 | 4 | private function extract(array $config, string $class): mixed |
|
25 | { |
||
26 | 4 | if (! isset($config['name'], $config['type'])) { |
|
27 | return $config; |
||
28 | } |
||
29 | |||
30 | 4 | if ($config['type'] instanceof Webonyx\Type) { |
|
31 | return $config; |
||
32 | } |
||
33 | |||
34 | 4 | $parameters = [ |
|
35 | 4 | 'name' => $config['name'], |
|
36 | 4 | 'type' => $config['type'], |
|
37 | 4 | 'mode' => $config['mode'] ?? 0, |
|
38 | 4 | 'description' => $config['description'] ?? null, |
|
39 | 4 | 'deprecationReason'=> $config['deprecationReason'] ?? null, |
|
40 | 4 | ]; |
|
41 | |||
42 | 4 | if (isset($config['defaultValue']) || \array_key_exists('defaultValue', $config)) { |
|
43 | 1 | $parameters['defaultValue'] = $config['defaultValue']; |
|
44 | } |
||
45 | |||
46 | 4 | return new $class(...$parameters); |
|
47 | } |
||
48 | } |
||
49 |