From 0be51b2adab748e9c1edf692334c468cf3e88e7e Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Thu, 28 Apr 2022 13:43:35 +0200 Subject: [PATCH] Prevent running code --- .../Analyser/AnalyserIntegrationTest.php | 8 +-- .../PHPStan/Analyser/data/discussion-7124.php | 50 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 4c392de11cb..71c365858e7 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -780,13 +780,13 @@ public function testDiscussion7124(): void $errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php'); $this->assertCount(4, $errors); $this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int, bool): bool given.', $errors[0]->getMessage()); - $this->assertSame(37, $errors[0]->getLine()); + $this->assertSame(38, $errors[0]->getLine()); $this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int): bool given.', $errors[1]->getMessage()); - $this->assertSame(44, $errors[1]->getLine()); + $this->assertSame(45, $errors[1]->getLine()); $this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[2]->getMessage()); - $this->assertSame(51, $errors[2]->getLine()); + $this->assertSame(52, $errors[2]->getLine()); $this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool): bool, Closure(int): bool given.', $errors[3]->getMessage()); - $this->assertSame(58, $errors[3]->getLine()); + $this->assertSame(59, $errors[3]->getLine()); } /** diff --git a/tests/PHPStan/Analyser/data/discussion-7124.php b/tests/PHPStan/Analyser/data/discussion-7124.php index 431af9f5532..4560c0954e8 100644 --- a/tests/PHPStan/Analyser/data/discussion-7124.php +++ b/tests/PHPStan/Analyser/data/discussion-7124.php @@ -31,30 +31,32 @@ function filter(array $array, ?callable $callback = null, int $mode = ARRAY_FILT : array_filter($array); } -// This one does fail, as both the value + key is asked and the key + value is used -filter( - [false, true, false], - static fn (int $key, bool $value): bool => 0 === $key % 2 && $value, - mode: ARRAY_FILTER_USE_BOTH, -); +function () { + // This one does fail, as both the value + key is asked and the key + value is used + filter( + [false, true, false], + static fn (int $key, bool $value): bool => 0 === $key % 2 && $value, + mode: ARRAY_FILTER_USE_BOTH, + ); -// This one should fail, as both the value + key is asked but only the key is used -filter( - [false, true, false], - static fn (int $key): bool => 0 === $key % 2, - mode: ARRAY_FILTER_USE_BOTH, -); + // This one should fail, as both the value + key is asked but only the key is used + filter( + [false, true, false], + static fn (int $key): bool => 0 === $key % 2, + mode: ARRAY_FILTER_USE_BOTH, + ); -// This one should fail, as only the key is asked but the value is used -filter( - [false, true, false], - static fn (bool $value): bool => $value, - mode: ARRAY_FILTER_USE_KEY, -); + // This one should fail, as only the key is asked but the value is used + filter( + [false, true, false], + static fn (bool $value): bool => $value, + mode: ARRAY_FILTER_USE_KEY, + ); -// This one should fail, as only the value is asked but the key is used -filter( - [false, true, false], - static fn (int $key): bool => 0 === $key % 2, - mode: 0, -); + // This one should fail, as only the value is asked but the key is used + filter( + [false, true, false], + static fn (int $key): bool => 0 === $key % 2, + mode: 0, + ); +};