Skip to content

Commit 0789c96

Browse files
phpstan-botclaude
andcommitted
Add regression test for no-effect array_map() with pure closure variable
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cf7ee51 commit 0789c96

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

tests/PHPStan/Rules/Functions/CallToFunctionStatementWithoutSideEffectsRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ public function testBug11101(): void
121121
]);
122122
}
123123

124+
public function testBug11101ClosureVariable(): void
125+
{
126+
$this->analyse([__DIR__ . '/data/bug-11101-closure-variable.php'], [
127+
[
128+
'Call to function array_map() on a separate line has no effect.',
129+
17,
130+
],
131+
]);
132+
}
133+
124134
#[RequiresPhp('>= 8.4.0')]
125135
public function testBug11101Php84(): void
126136
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11101ClosureVariable;
4+
5+
class Foo
6+
{
7+
8+
/** @param list<string> $args */
9+
public function test(array $args): void
10+
{
11+
$pureFx = static function (string $v): void {};
12+
13+
assert(isset($args[0]));
14+
15+
$pureFx($args[0]);
16+
17+
array_map($pureFx, $args);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)