From afd044422e95b1ecda0e6515db483efa90d0ddcf Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 21 May 2025 23:40:26 +0200 Subject: [PATCH 1/3] Avoid error with constant $ --- .../BetterReflection/BetterReflectionProvider.php | 2 ++ .../PHPStan/Analyser/AnalyserIntegrationTest.php | 6 ++++++ tests/PHPStan/Analyser/data/bug-12095.php | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-12095.php diff --git a/src/Reflection/BetterReflection/BetterReflectionProvider.php b/src/Reflection/BetterReflection/BetterReflectionProvider.php index 6ae28ec9c6..427cf10af6 100644 --- a/src/Reflection/BetterReflection/BetterReflectionProvider.php +++ b/src/Reflection/BetterReflection/BetterReflectionProvider.php @@ -434,6 +434,8 @@ public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $nam return true; } catch (IdentifierNotFound) { // pass + } catch (InvalidIdentifierName) { + // pass } catch (UnableToCompileNode) { // pass } diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 1e5491bbc3..61ff4a3c1d 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1493,6 +1493,12 @@ public function testBug12979(): void $this->assertNoErrors($errors); } + public function testBug12095(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-12095.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/bug-12095.php b/tests/PHPStan/Analyser/data/bug-12095.php new file mode 100644 index 0000000000..54c41421fd --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-12095.php @@ -0,0 +1,15 @@ + Date: Thu, 22 May 2025 17:35:08 +0200 Subject: [PATCH 2/3] Update baseline --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 47ac0acf51..117ed792d4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -244,6 +244,11 @@ parameters: count: 1 path: src/Reflection/BetterReflection/BetterReflectionProvider.php + - + message: "#^Dead catch \\- PHPStan\\\\BetterReflection\\\\NodeCompiler\\\\Exception\\\\InvalidIdentifierName is never thrown in the try block\\.$#" + count: 3 + path: src/Reflection/BetterReflection/BetterReflectionProvider.php + - message: "#^Creating new ReflectionClass is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine\\. Use objects retrieved from ReflectionProvider instead\\.$#" count: 1 From 54b6023a7d91401a5240b8cdea970793ef68bff4 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 25 May 2025 12:19:34 +0200 Subject: [PATCH 3/3] Fix --- phpstan-baseline.neon | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 117ed792d4..b8fb0297a6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -236,7 +236,7 @@ parameters: - message: "#^Dead catch \\- PHPStan\\\\BetterReflection\\\\Identifier\\\\Exception\\\\InvalidIdentifierName is never thrown in the try block\\.$#" - count: 3 + count: 4 path: src/Reflection/BetterReflection/BetterReflectionProvider.php - @@ -244,11 +244,6 @@ parameters: count: 1 path: src/Reflection/BetterReflection/BetterReflectionProvider.php - - - message: "#^Dead catch \\- PHPStan\\\\BetterReflection\\\\NodeCompiler\\\\Exception\\\\InvalidIdentifierName is never thrown in the try block\\.$#" - count: 3 - path: src/Reflection/BetterReflection/BetterReflectionProvider.php - - message: "#^Creating new ReflectionClass is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine\\. Use objects retrieved from ReflectionProvider instead\\.$#" count: 1