diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 25d0dc729a..821be9f377 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -124,6 +124,10 @@ jobs: mv src/Foo.php.orig src/Foo.php echo -n > phpstan-baseline.neon ../../bin/phpstan -vvv + - script: | + cd e2e/bug-14514 + composer install + ../../bin/phpstan analyze bug-14515.php - script: | cd e2e/bug10449 ../../bin/phpstan analyze diff --git a/e2e/bug-14514/.gitignore b/e2e/bug-14514/.gitignore new file mode 100644 index 0000000000..61ead86667 --- /dev/null +++ b/e2e/bug-14514/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/e2e/bug-14514/autoloader.php b/e2e/bug-14514/autoloader.php new file mode 100644 index 0000000000..908d41797e --- /dev/null +++ b/e2e/bug-14514/autoloader.php @@ -0,0 +1,7 @@ +getType($expr); - $toStringMethod = $scope->getMethodReflection($exprType, '__toString'); + + $toStringMethod = null; + if (!$exprType->isObject()->no()) { + $toStringMethod = $scope->getMethodReflection($exprType, '__toString'); + } if ($toStringMethod === null) { return new ExpressionResult( $scope, diff --git a/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php b/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php index 9fa246f555..8e172d035a 100644 --- a/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php +++ b/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php @@ -214,4 +214,9 @@ public function testBug14504(): void $this->analyse([__DIR__ . '/data/bug-14504.php'], []); } + public function testBug14511(): void + { + $this->analyse([__DIR__ . '/data/bug-14511.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php index 2b896c17b1..88bb38c5d4 100644 --- a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php +++ b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php @@ -383,4 +383,10 @@ public function testBug14504(): void $this->analyse([__DIR__ . '/data/bug-14504-method.php'], []); } + public function testBug14511(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-14511-method.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Pure/data/bug-14511-method.php b/tests/PHPStan/Rules/Pure/data/bug-14511-method.php new file mode 100644 index 0000000000..5b8b15030a --- /dev/null +++ b/tests/PHPStan/Rules/Pure/data/bug-14511-method.php @@ -0,0 +1,47 @@ +