From e4327da3784dc6fd753f16ee18e310686ff14e5c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 26 Feb 2025 21:17:41 +0100 Subject: [PATCH 1/3] Add 11015 regression test --- .../WrongVariableNameInVarTagRuleTest.php | 9 +++++++ tests/PHPStan/Rules/PhpDoc/data/bug-11015.php | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/PHPStan/Rules/PhpDoc/data/bug-11015.php diff --git a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php index c4bb1aec92..5f6b972486 100644 --- a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php @@ -197,6 +197,15 @@ public function testBug12458(): void $this->analyse([__DIR__ . '/data/bug-12458.php'], []); } + public function testBug11015(): void + { + $this->checkTypeAgainstNativeType = true; + $this->checkTypeAgainstPhpDocType = true; + $this->strictWideningCheck = true; + + $this->analyse([__DIR__ . '/data/bug-11015.php'], []); + } + public function testEnums(): void { if (PHP_VERSION_ID < 80100) { diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-11015.php b/tests/PHPStan/Rules/PhpDoc/data/bug-11015.php new file mode 100644 index 0000000000..2b648f77d7 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-11015.php @@ -0,0 +1,25 @@ +fetch(); + if (empty($b)) { + return; + } + + /** @var array $b */ + echo $b['a']; + } + + public function sayHello2(PDOStatement $date): void + { + $b = $date->fetch(); + + /** @var array $b */ + echo $b['a']; + } +} From 9daae6df1ebd16f98acb772ca56c4b70b1d020bf Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 26 Feb 2025 21:18:55 +0100 Subject: [PATCH 2/3] Add 10861 regression test --- .../WrongVariableNameInVarTagRuleTest.php | 9 ++++++++ tests/PHPStan/Rules/PhpDoc/data/bug-10861.php | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/PHPStan/Rules/PhpDoc/data/bug-10861.php diff --git a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php index 5f6b972486..2b7bb4bd09 100644 --- a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php @@ -206,6 +206,15 @@ public function testBug11015(): void $this->analyse([__DIR__ . '/data/bug-11015.php'], []); } + public function testBug10861(): void + { + $this->checkTypeAgainstNativeType = true; + $this->checkTypeAgainstPhpDocType = true; + $this->strictWideningCheck = true; + + $this->analyse([__DIR__ . '/data/bug-10861.php'], []); + } + public function testEnums(): void { if (PHP_VERSION_ID < 80100) { diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-10861.php b/tests/PHPStan/Rules/PhpDoc/data/bug-10861.php new file mode 100644 index 0000000000..a9116442b1 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-10861.php @@ -0,0 +1,23 @@ + $array1 + * @param-out array $array1 + */ + public function sayHello(array &$array1): void + { + $values_1 = $array1; + + $values_1 = array_filter($values_1, function (mixed $value): bool { + return $value !== []; + }); + + /** @var array $values_1 */ + $array1 = $values_1; + } +} From 5b67b5ebe71fd7049bee0600dece6b715f6240b7 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 26 Feb 2025 21:23:00 +0100 Subject: [PATCH 3/3] Add 11535 regression test --- .../WrongVariableNameInVarTagRuleTest.php | 9 +++++++++ tests/PHPStan/Rules/PhpDoc/data/bug-11535.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/PHPStan/Rules/PhpDoc/data/bug-11535.php diff --git a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php index 2b7bb4bd09..9269379387 100644 --- a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php @@ -215,6 +215,15 @@ public function testBug10861(): void $this->analyse([__DIR__ . '/data/bug-10861.php'], []); } + public function testBug11535(): void + { + $this->checkTypeAgainstNativeType = true; + $this->checkTypeAgainstPhpDocType = true; + $this->strictWideningCheck = true; + + $this->analyse([__DIR__ . '/data/bug-11535.php'], []); + } + public function testEnums(): void { if (PHP_VERSION_ID < 80100) { diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-11535.php b/tests/PHPStan/Rules/PhpDoc/data/bug-11535.php new file mode 100644 index 0000000000..17feae9b10 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-11535.php @@ -0,0 +1,18 @@ + */ +$a = function(string $b) { + return [1,2,3]; +}; + +/** @var \Closure(array): array */ +$a = function(array $b) { + return $b; +}; + +/** @var \Closure(string): string */ +$a = function(string $b) { + return $b; +};