Passed
Pull Request — master (#20)
by Christoffer
02:08
created

DeprecationTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isDeprecated() 0 3 1
A setDeprecationReason() 0 9 2
A setIsDeprecated() 0 3 1
A getDeprecationReason() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Type\Definition;
4
5
trait DeprecationTrait
6
{
7
8
    /**
9
     * @var ?string
10
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ?string at position 0 could not be parsed: Unknown type name '?string' at position 0 in ?string.
Loading history...
11
    private $deprecationReason;
12
13
    /**
14
     * @var bool
15
     */
16
    private $isDeprecated = false;
17
18
    /**
19
     * @return null|string
20
     */
21
    public function getDeprecationReason(): ?string
22
    {
23
        return $this->deprecationReason;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29
    public function isDeprecated(): bool
30
    {
31
        return $this->isDeprecated;
32
    }
33
34
    /**
35
     * @param null|string $deprecationReason
36
     * @return $this
37
     */
38
    protected function setDeprecationReason(?string $deprecationReason)
39
    {
40
        if ($deprecationReason) {
41
            $this->isDeprecated = true;
42
        }
43
44
        $this->deprecationReason = $deprecationReason;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @param bool $isDeprecated
51
     * @throws \TypeError
52
     */
53
    public function setIsDeprecated(bool $isDeprecated): void
0 ignored issues
show
Unused Code introduced by
The parameter $isDeprecated is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    public function setIsDeprecated(/** @scrutinizer ignore-unused */ bool $isDeprecated): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        throw new \TypeError('You should provide "deprecationReason" instead of "isDeprecated".');
56
    }
57
}
58