Skip to content

Commit 761c482

Browse files
ondrejmirtesclaude
andcommitted
Add regression tests for #13304 and #13643
Closes phpstan/phpstan#13304 Closes phpstan/phpstan#13643 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b191178 commit 761c482

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13304;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function foo(object $bar): void
8+
{
9+
foreach (['qux', 'quux'] as $property) {
10+
if (!property_exists($bar, $property)) {
11+
throw new \Exception;
12+
}
13+
}
14+
15+
assertType("object&hasProperty(quux)&hasProperty(qux)", $bar);
16+
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,4 +2843,11 @@ public function testBug11533(): void
28432843
$this->analyse([__DIR__ . '/data/bug-11533.php'], []);
28442844
}
28452845

2846+
public function testBug13643(): void
2847+
{
2848+
$this->checkExplicitMixed = true;
2849+
$this->checkImplicitMixed = true;
2850+
$this->analyse([__DIR__ . '/data/bug-13643.php'], []);
2851+
}
2852+
28462853
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13643;
4+
5+
/**
6+
* @param list<array<string, mixed>> $records
7+
*/
8+
function testA(array $records): void {
9+
foreach ($records as $record) {
10+
foreach (['aaa', 'bbb', 'ccc', 'ddd'] as $col) {
11+
if (!array_key_exists($col, $record) || !is_int($record[$col])) {
12+
$record[$col] = 0;
13+
}
14+
}
15+
16+
useRecord(
17+
$record['aaa'],
18+
$record['bbb'],
19+
$record['ccc'],
20+
$record['ddd'],
21+
);
22+
}
23+
}
24+
25+
/**
26+
* @param list<array<string, mixed>> $records
27+
*/
28+
function testB(array $records): void {
29+
foreach ($records as $record) {
30+
foreach (['aaa', 'bbb', 'ccc', 'ddd'] as $col) {
31+
if (array_key_exists($col, $record) && is_int($record[$col])) {
32+
continue;
33+
}
34+
$record[$col] = 0;
35+
}
36+
37+
useRecord(
38+
$record['aaa'],
39+
$record['bbb'],
40+
$record['ccc'],
41+
$record['ddd'],
42+
);
43+
}
44+
}
45+
46+
function useRecord(int ...$v): void {}

0 commit comments

Comments
 (0)