Test Failed
Push — master ( da2c9c...d0cc4d )
by Kirill
02:03
created

AbstractTypeDefinition::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection;
11
12
use Railt\Reflection\Contracts\Definition\TypeDefinition;
13
use Railt\Reflection\Definition\Behaviour\HasDeprecation;
14
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
15
16
/**
17
 * Class AbstractTypeDefinition
18
 */
19
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition
20
{
21
    use HasDirectives;
22
    use HasDeprecation;
23
24
    /**
25
     * @var string
26
     */
27
    protected $name;
28
29
    /**
30
     * @var string|null
31
     */
32
    protected $description;
33
34
    /**
35
     * AbstractTypeDefinition constructor.
36
     * @param Document $document
37
     * @param string $name
38
     */
39 2
    public function __construct(Document $document, string $name)
40
    {
41 2
        $this->name = $name;
42
43 2
        parent::__construct($document);
44
45 2
        $document->addTypeDefinition($this);
46 2
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getDescription(): string
52
    {
53
        return (string)$this->description;
54
    }
55
56
    /**
57
     * @param null|string $description
58
     */
59
    public function setDescription(?string $description): void
60
    {
61
        $this->description = $description;
62
    }
63
64
    /**
65
     * @param TypeDefinition $definition
66
     * @return bool
67
     */
68
    public function instanceOf(TypeDefinition $definition): bool
69
    {
70
        return $this instanceof $definition;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 2
    public function getName(): string
77
    {
78 2
        return $this->name;
79
    }
80
81
    /**
82
     * @param string $type
83
     * @return TypeDefinition
84
     */
85
    protected function fetch(string $type): TypeDefinition
86
    {
87
        return $this->document->getReflection()->get($type, $this);
88
    }
89
}
90