Field   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
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 34
ccs 11
cts 11
cp 1
rs 10

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
    /**
20
     * @var Argument[]
21
     */
22
    public array $args = [];
23
24
    public null|string|Type $type = null;
25
26
    /**
27
     * @param null|string $name Can be used to alias the field
28
     * @param null|string $type FQCN of PHP class implementing the GraphQL type, see README.md#type-syntax
29
     */
30 17
    public function __construct(
31
        public ?string $name = null,
32
        ?string $type = null,
33
        public ?string $description = null,
34
    ) {
35 17
        $this->type = $type;
36
    }
37
38 11
    public function toArray(): array
39
    {
40 11
        $args = [];
41 11
        foreach ($this->args as $arg) {
42 7
            $args[] = $arg->toArray();
43
        }
44
45 11
        return [
46 11
            'name' => $this->name,
47 11
            'type' => $this->type,
48 11
            'description' => $this->description,
49 11
            'args' => $args,
50 11
        ];
51
    }
52
}
53