Test Failed
Push — master ( 4bdf7b...97fe68 )
by Kirill
02:15
created

AbstractTypeDefinition::renameTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Definition\Behaviour\HasInheritance;
15
use Railt\Reflection\Definition\Behaviour\HasName;
16
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
17
18
/**
19
 * Class AbstractTypeDefinition
20
 */
21
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition
22
{
23
    use HasName;
24
    use HasDirectives;
25
    use HasDeprecation;
26
    use HasInheritance;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $description;
32
33
    /**
34
     * AbstractTypeDefinition constructor.
35
     * @param Document|\Railt\Reflection\Contracts\Document $document
36
     * @param string $name
37
     */
38 9
    public function __construct(Document $document, string $name)
39
    {
40 9
        $this->renameTo($name);
41 9
        parent::__construct($document);
42 9
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getDescription(): string
48
    {
49
        return (string)$this->description;
50
    }
51
52
    /**
53
     * @param null|string $description
54
     * @return TypeDefinition|$this
55
     */
56 9
    public function withDescription(?string $description): TypeDefinition
57
    {
58 9
        $this->description = $description;
59
60 9
        return $this;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isBuiltin(): bool
67
    {
68
        return false;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function __toString(): string
75
    {
76
        return \sprintf('%s<%s>', $this->name ?? '?', static::getType());
77
    }
78
}
79