/
PHPDefineConstant.php
63 lines (50 loc) · 1.51 KB
/
PHPDefineConstant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace voku\SimplePhpParser\Model;
use PhpParser\Node\Expr\FuncCall;
use voku\SimplePhpParser\Parsers\Helper\Utils;
class PHPDefineConstant extends PHPConst
{
/**
* @param FuncCall $node
* @param null $dummy
*
* @return $this
*/
public function readObjectFromPhpNode($node, $dummy = null): PHPConst
{
$this->prepareNode($node);
if (
isset($node->args[0])
&&
\property_exists($node->args[0], 'value')
&&
\property_exists($node->args[0]->value, 'value')
) {
$constName = $this->getConstantFQN($node, (string)$node->args[0]->value->value);
} else {
$constName = '';
}
if (\in_array($constName, ['null', 'true', 'false'], true)) {
$constName = \strtoupper($constName);
}
$this->name = $constName;
/* @phpstan-ignore-next-line */
$this->value = Utils::getPhpParserValueFromNode($node->args[1]);
$this->type = Utils::normalizePhpType(\gettype($this->value));
$this->collectTags($node);
return $this;
}
/**
* @param \ReflectionClassConstant $constant
*
* @return $this
*/
public function readObjectFromReflection($constant): PHPConst
{
$this->name = $constant->getName();
$this->value = $constant->getValue();
$this->type = Utils::normalizePhpType(\gettype($this->value));
return $this;
}
}