diff --git a/src/Reflection/InitializerExprContext.php b/src/Reflection/InitializerExprContext.php index 65568cd890..1818d15e92 100644 --- a/src/Reflection/InitializerExprContext.php +++ b/src/Reflection/InitializerExprContext.php @@ -47,7 +47,7 @@ private static function parseNamespace(string $name): ?string { $parts = explode('\\', $name); if (count($parts) > 1) { - return implode('\\', array_slice($parts, 0, 1)); + return implode('\\', array_slice($parts, 0, -1)); } return null; diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php index 5e1bbacf75..e033737170 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php @@ -49,4 +49,9 @@ public function testBug7352(): void $this->analyse([__DIR__ . '/data/bug-7352.php'], []); } + public function testBug7352WithSubNamespace(): void + { + $this->analyse([__DIR__ . '/data/bug-7352-with-sub-namespace.php'], []); + } + } diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-7352-with-sub-namespace.php b/tests/PHPStan/Rules/PhpDoc/data/bug-7352-with-sub-namespace.php new file mode 100644 index 0000000000..a9b87c2cf7 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-7352-with-sub-namespace.php @@ -0,0 +1,11 @@ +