Argument   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A hasDefaultValue() 0 4 2
A getDeprecationReason() 0 4 1
A getDefaultValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Argument;
6
7
use Andi\GraphQL\Definition\Field\DefaultValueAwareInterface;
8
use Andi\GraphQL\Definition\Field\DeprecationReasonAwareInterface;
9
10
class Argument extends AbstractArgument implements DefaultValueAwareInterface, DeprecationReasonAwareInterface
11
{
12
    private readonly string $deprecationReason;
13
    private readonly mixed $defaultValue;
14
15 1
    public function __construct(
16
        string  $name,
17
        string  $type,
18
        int $mode = 0,
19
        ?string $description = null,
20
        ?string $deprecationReason = null,
21
        mixed $defaultValue = null,
22
    ) {
23 1
        parent::__construct($name, $type, $mode, $description);
24
25 1
        if (null !== $deprecationReason) {
26 1
            $this->deprecationReason = $deprecationReason;
0 ignored issues
show
Bug introduced by
The property deprecationReason is declared read-only in Andi\GraphQL\Argument\Argument.
Loading history...
27
        }
28
29 1
        if (\func_num_args() >= 6) {
30 1
            $this->defaultValue = $defaultValue;
0 ignored issues
show
Bug introduced by
The property defaultValue is declared read-only in Andi\GraphQL\Argument\Argument.
Loading history...
31
        }
32
    }
33
34 1
    public function getDeprecationReason(): ?string
35
    {
36
        /** @psalm-suppress RedundantPropertyInitializationCheck */
37 1
        return $this->deprecationReason ?? null;
38
    }
39
40 1
    public function hasDefaultValue(): bool
41
    {
42 1
        return isset($this->defaultValue)
43 1
            || (new \ReflectionProperty($this, 'defaultValue'))->isInitialized($this);
44
    }
45
46 1
    public function getDefaultValue(): mixed
47
    {
48 1
        return $this->defaultValue;
49
    }
50
}
51