Test Failed
Push — master ( 3b7232...dbe410 )
by Kirill
02:20
created

AbstractTypeDefinition::setDescription()   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 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Contracts\Dictionary;
14
use Railt\Reflection\Definition\Behaviour\HasDeprecation;
15
use Railt\Reflection\Definition\Behaviour\HasInheritance;
16
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
17
18
/**
19
 * Class AbstractTypeDefinition
20
 */
21
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition
22
{
23
    use HasDirectives;
24
    use HasDeprecation;
25
    use HasInheritance;
26
27
    /**
28
     * @var string
29
     */
30
    protected $name;
31
32
    /**
33
     * @var string|null
34
     */
35
    protected $description;
36
37
    /**
38
     * AbstractTypeDefinition constructor.
39
     * @param Document $document
40
     * @param string $name
41
     */
42 9
    public function __construct(Document $document, string $name)
43
    {
44 9
        $this->name = $name;
45
46 9
        parent::__construct($document);
47 9
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getDescription(): string
53
    {
54
        return (string)$this->description;
55
    }
56
57
    /**
58
     * @param null|string $description
59
     * @return TypeDefinition|$this
60
     */
61 9
    public function withDescription(?string $description): TypeDefinition
62
    {
63 9
        $this->description = $description;
64
65 9
        return $this;
66
    }
67
68
    /**
69
     * @param string $name
70
     * @return TypeDefinition|$this
71
     */
72 6
    public function renameTo(string $name): TypeDefinition
73
    {
74 6
        $this->name = $name;
75
76 6
        return $this;
77
    }
78
79
    /**
80
     * @return Dictionary
81
     */
82 6
    public function getDictionary(): Dictionary
83
    {
84 6
        return $this->document->getDictionary();
85
    }
86
87
    /**
88
     * @param TypeDefinition $definition
89
     * @return bool
90
     */
91 6
    public function instanceOf(TypeDefinition $definition): bool
92
    {
93 6
        if ($definition::getType()->is(Type::ANY)) {
94 6
            return true;
95
        }
96
97 6
        if ($this->getName() === $definition->getName()) {
98 6
            return true;
99
        }
100
101 6
        return $this->isExtendsDefinition($definition);
102
    }
103
104
    /**
105
     * @return string
106
     */
107 16
    public function __toString(): string
108
    {
109 16
        return \sprintf('%s<%s>', $this->getName(), static::getType());
110
    }
111
112
    /**
113
     * @return string
114
     */
115 40
    public function getName(): string
116
    {
117 40
        return $this->name;
118
    }
119
}
120