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|\Railt\Reflection\Contracts\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
|
8 |
|
public function renameTo(string $name): TypeDefinition |
73
|
|
|
{ |
74
|
8 |
|
$this->name = $name; |
75
|
|
|
|
76
|
8 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
25 |
|
public function getName(): string |
83
|
|
|
{ |
84
|
25 |
|
return $this->name; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function __toString(): string |
91
|
|
|
{ |
92
|
|
|
return \sprintf('%s<%s>', $this->name ?? '?', static::getType()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|