|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gskema\TypeSniff\Inspection\Subject; |
|
4
|
|
|
|
|
5
|
|
|
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnConstElement; |
|
6
|
|
|
use Gskema\TypeSniff\Core\DocBlock\DocBlock; |
|
7
|
|
|
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag; |
|
8
|
|
|
use Gskema\TypeSniff\Core\Type\Common\UndefinedType; |
|
9
|
|
|
use Gskema\TypeSniff\Core\Type\TypeInterface; |
|
10
|
|
|
|
|
11
|
|
|
class ConstTypeSubject extends AbstractTypeSubject |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param TypeInterface|null $docType |
|
15
|
|
|
* @param TypeInterface|null $valueType |
|
16
|
|
|
* @param int|null $docTypeLine |
|
17
|
|
|
* @param int $fnTypeLine |
|
18
|
|
|
* @param string $name |
|
19
|
|
|
* @param DocBlock $docBlock |
|
20
|
|
|
* @param string[] $attributeNames |
|
21
|
|
|
* @param string $id |
|
22
|
|
|
*/ |
|
23
|
7 |
|
public function __construct( |
|
24
|
|
|
?TypeInterface $docType, |
|
25
|
|
|
?TypeInterface $valueType, |
|
26
|
|
|
?int $docTypeLine, |
|
27
|
|
|
int $fnTypeLine, |
|
28
|
|
|
string $name, |
|
29
|
|
|
DocBlock $docBlock, |
|
30
|
|
|
array $attributeNames, |
|
31
|
|
|
string $id |
|
32
|
|
|
) { |
|
33
|
7 |
|
parent::__construct( |
|
34
|
7 |
|
$docType, |
|
35
|
7 |
|
new UndefinedType(), // not in PHP 7.4 :( |
|
36
|
|
|
$valueType, |
|
37
|
|
|
$docTypeLine, |
|
38
|
|
|
$fnTypeLine, |
|
39
|
|
|
$name, |
|
40
|
|
|
$docBlock, |
|
41
|
|
|
$attributeNames, |
|
42
|
|
|
$id |
|
43
|
|
|
); |
|
44
|
7 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param AbstractFqcnConstElement $const |
|
48
|
|
|
* |
|
49
|
|
|
* @return static |
|
50
|
|
|
*/ |
|
51
|
7 |
|
public static function fromElement(AbstractFqcnConstElement $const) |
|
52
|
|
|
{ |
|
53
|
7 |
|
$docBlock = $const->getDocBlock(); |
|
54
|
|
|
|
|
55
|
|
|
/** @var VarTag|null $varTag */ |
|
56
|
7 |
|
$varTag = $docBlock->getTagsByName('var')[0] ?? null; |
|
57
|
|
|
|
|
58
|
7 |
|
return new static( |
|
59
|
7 |
|
$varTag ? $varTag->getType() : null, |
|
60
|
7 |
|
$const->getValueType(), |
|
61
|
7 |
|
$varTag ? $varTag->getLine() : null, |
|
62
|
7 |
|
$const->getLine(), |
|
63
|
7 |
|
$const->getConstName() . ' constant', |
|
64
|
|
|
$docBlock, |
|
65
|
7 |
|
$const->getAttributeNames(), |
|
66
|
7 |
|
$const->getFqcn() . '::' . $const->getConstName() |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|