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

Field::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 6
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 3
crap 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