Skip to content

Commit 2a19995

Browse files
committed
Allow getting type from define() node
- fixes #286
1 parent b1cc7bf commit 2a19995

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/DefinitionResolver.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ private static function resolveClassNameToType(Node $class): Type
725725
*/
726726
public function getTypeFromNode(Node $node)
727727
{
728+
if (
729+
$node instanceof Node\Expr\FuncCall
730+
&& $node->name instanceof Node\Name
731+
&& strtolower((string)$node->name) === 'define'
732+
&& isset($node->args[0])
733+
&& $node->args[0]->value instanceof Node\Scalar\String_
734+
&& isset($node->args[1])
735+
) {
736+
// constants with define() like
737+
// define('TEST_DEFINE_CONSTANT', false);
738+
return $this->resolveExpressionNodeToType($node->args[1]->value);
739+
}
740+
728741
if ($node instanceof Node\Param) {
729742
// Parameters
730743
$docBlock = $node->getAttribute('parentNode')->getAttribute('docBlock');
@@ -883,7 +896,7 @@ public static function getDefinedFqn(Node $node)
883896
return (string)$class->namespacedName . '::' . $node->name;
884897
}
885898
} else if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && strtolower((string)$node->name) === 'define') {
886-
if (!isset($node->args[0]) || !($node->args[0]->value instanceof Node\Scalar\String_)) {
899+
if (!isset($node->args[0]) || !($node->args[0]->value instanceof Node\Scalar\String_) || !isset($node->args[1])) {
887900
return null;
888901
}
889902
return (string)$node->args[0]->value->value;

src/Protocol/SymbolInformation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static function fromNode(Node $node, string $fqn = null)
5757
&& strtolower((string)$node->name) === 'define'
5858
&& isset($node->args[0])
5959
&& $node->args[0]->value instanceof Node\Scalar\String_
60+
&& isset($node->args[1])
6061
) {
6162
// constants with define() like
6263
// define('TEST_DEFINE_CONSTANT', false);
@@ -90,7 +91,7 @@ public static function fromNode(Node $node, string $fqn = null)
9091
} else {
9192
return null;
9293
}
93-
94+
9495
if (!isset($symbol->name)) {
9596
if ($node instanceof Node\Name) {
9697
$symbol->name = (string)$node;

0 commit comments

Comments
 (0)