Failed Conditions
Push — master ( 05fc61...964283 )
by Adrien
02:24
created

Field   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 12 2
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Attribute;
6
7
use Attribute;
8
use GraphQL\Type\Definition\Type;
9
10
/**
11
 * Attribute used to override values for an output field in GraphQL.
12
 *
13
 * All values are optional and should only be used to override
14
 * what is declared by the original method.
15
 */
16
#[Attribute(Attribute::TARGET_METHOD)]
17
final class Field implements ApiAttribute
18
{
19
    public array $args = [];
20
21
    public null|string|Type $type = null;
22
23
    /**
24
     * @param null|string $name Can be used to alias the field
25
     * @param null|string $type FQCN of PHP class implementing the GraphQL type
26
     */
27 15
    public function __construct(
28
        public ?string $name = null,
29
        null|string $type = null,
30
        public ?string $description = null,
31
    ) {
32 15
        $this->type = $type;
33
    }
34
35 9
    public function toArray(): array
36
    {
37 9
        $args = [];
38 9
        foreach ($this->args as $arg) {
39 6
            $args[] = $arg->toArray();
40
        }
41
42
        return [
43 9
            'name' => $this->name,
44 9
            'type' => $this->type,
45 9
            'description' => $this->description,
46
            'args' => $args,
47
        ];
48
    }
49
}
50