diff --git a/src/Definition.php b/src/Definition.php index 0459ff3..c40e8a8 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -20,10 +20,10 @@ class Definition * - testFunction() * - TestNamespace\TestClass * - TestNamespace\TestClass::TEST_CONSTANT - * - TestNamespace\TestClass::staticTestProperty - * - TestNamespace\TestClass::testProperty + * - TestNamespace\TestClass::$staticTestProperty + * - TestNamespace\TestClass->testProperty * - TestNamespace\TestClass::staticTestMethod() - * - TestNamespace\TestClass::testMethod() + * - TestNamespace\TestClass->testMethod() * * @var string|null */ diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index b90d7b3..e9e5eac 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -221,7 +221,7 @@ class DefinitionResolver } else { $classFqn = substr((string)$varType->getFqsen(), 1); } - $name = $classFqn . '::' . (string)$node->name; + $name = $classFqn . '->' . (string)$node->name; } else if ($parent instanceof Node\Expr\FuncCall) { if ($parent->name instanceof Node\Expr) { return null; @@ -255,7 +255,11 @@ class DefinitionResolver $className = (string)$classNode->namespacedName; } } - $name = (string)$className . '::' . $node->name; + if ($node instanceof Node\Expr\StaticPropertyFetch) { + $name = (string)$className . '::$' . $node->name; + } else { + $name = (string)$className . '::' . $node->name; + } } else { return null; } @@ -404,7 +408,7 @@ class DefinitionResolver } else { $classFqn = substr((string)$t->getFqsen(), 1); } - $fqn = $classFqn . '::' . $expr->name; + $fqn = $classFqn . '->' . $expr->name; if ($expr instanceof Node\Expr\MethodCall) { $fqn .= '()'; } @@ -423,7 +427,11 @@ class DefinitionResolver if (!($classType instanceof Types\Object_) || $classType->getFqsen() === null || $expr->name instanceof Node\Expr) { return new Types\Mixed; } - $fqn = substr((string)$classType->getFqsen(), 1) . '::' . $expr->name; + $fqn = substr((string)$classType->getFqsen(), 1) . '::'; + if ($expr instanceof Node\Expr\StaticPropertyFetch) { + $fqn .= '$'; + } + $fqn .= $expr->name; if ($expr instanceof Node\Expr\StaticCall) { $fqn .= '()'; } @@ -735,21 +743,31 @@ class DefinitionResolver // Function: use functionName() as the name return (string)$node->namespacedName . '()'; } else if ($node instanceof Node\Stmt\ClassMethod) { - // Class method: use ClassName::methodName() as name + // Class method: use ClassName->methodName() as name $class = $node->getAttribute('parentNode'); if (!isset($class->name)) { // Ignore anonymous classes return null; } - return (string)$class->namespacedName . '::' . (string)$node->name . '()'; + if ($node->isStatic()) { + return (string)$class->namespacedName . '::' . (string)$node->name . '()'; + } else { + return (string)$class->namespacedName . '->' . (string)$node->name . '()'; + } } else if ($node instanceof Node\Stmt\PropertyProperty) { - // Property: use ClassName::propertyName as name - $class = $node->getAttribute('parentNode')->getAttribute('parentNode'); + $property = $node->getAttribute('parentNode'); + $class = $property->getAttribute('parentNode'); if (!isset($class->name)) { // Ignore anonymous classes return null; } - return (string)$class->namespacedName . '::' . (string)$node->name; + if ($property->isStatic()) { + // Static Property: use ClassName::$propertyName as name + return (string)$class->namespacedName . '::$' . (string)$node->name; + } else { + // Instance Property: use ClassName->propertyName as name + return (string)$class->namespacedName . '->' . (string)$node->name; + } } else if ($node instanceof Node\Const_) { $parent = $node->getAttribute('parentNode'); if ($parent instanceof Node\Stmt\Const_) { diff --git a/src/Protocol/SymbolInformation.php b/src/Protocol/SymbolInformation.php index 1111dc0..06e8f7e 100644 --- a/src/Protocol/SymbolInformation.php +++ b/src/Protocol/SymbolInformation.php @@ -88,7 +88,7 @@ class SymbolInformation } $symbol->location = Location::fromNode($node); if ($fqn !== null) { - $parts = preg_split('/(::|\\\\)/', $fqn); + $parts = preg_split('/(::|->|\\\\)/', $fqn); array_pop($parts); $symbol->containerName = implode('\\', $parts); } diff --git a/tests/NodeVisitor/DefinitionCollectorTest.php b/tests/NodeVisitor/DefinitionCollectorTest.php index ded65d1..6768c94 100644 --- a/tests/NodeVisitor/DefinitionCollectorTest.php +++ b/tests/NodeVisitor/DefinitionCollectorTest.php @@ -33,10 +33,10 @@ class DefinitionCollectorTest extends TestCase 'TestNamespace\\TEST_CONST', 'TestNamespace\\TestClass', 'TestNamespace\\TestClass::TEST_CLASS_CONST', - 'TestNamespace\\TestClass::staticTestProperty', - 'TestNamespace\\TestClass::testProperty', + 'TestNamespace\\TestClass::$staticTestProperty', + 'TestNamespace\\TestClass->testProperty', 'TestNamespace\\TestClass::staticTestMethod()', - 'TestNamespace\\TestClass::testMethod()', + 'TestNamespace\\TestClass->testMethod()', 'TestNamespace\\TestTrait', 'TestNamespace\\TestInterface', 'TestNamespace\\test_function()' @@ -44,10 +44,10 @@ class DefinitionCollectorTest extends TestCase $this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TEST_CONST']); $this->assertInstanceOf(Node\Stmt\Class_::class, $defNodes['TestNamespace\\TestClass']); $this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TestClass::TEST_CLASS_CONST']); - $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::staticTestProperty']); - $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::testProperty']); + $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::$staticTestProperty']); + $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass->testProperty']); $this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass::staticTestMethod()']); - $this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass::testMethod()']); + $this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass->testMethod()']); $this->assertInstanceOf(Node\Stmt\Trait_::class, $defNodes['TestNamespace\\TestTrait']); $this->assertInstanceOf(Node\Stmt\Interface_::class, $defNodes['TestNamespace\\TestInterface']); $this->assertInstanceOf(Node\Stmt\Function_::class, $defNodes['TestNamespace\\test_function()']);