Issues (169)

src/Argument/Argument.php (2 issues)

Labels
Severity
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
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
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