Skip to content

Commit c459510

Browse files
phpstan-botclaude
andcommitted
Add test case with union @throws annotation in bug-9349 test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6539a4a commit c459510

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,10 @@ public function testBug9349(): void
14151415
'Variable $sql might not be defined.',
14161416
19,
14171417
],
1418+
[
1419+
'Variable $sql might not be defined.',
1420+
78,
1421+
],
14181422
]);
14191423
}
14201424

tests/PHPStan/Rules/Variables/data/bug-9349.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,35 @@ public function maybeThrows2(): void
6060
}
6161
}
6262
}
63+
64+
class HelloWorld3
65+
{
66+
public function test3(): void
67+
{
68+
global $pdo;
69+
70+
try {
71+
$this->maybeThrows3();
72+
$sql = "SELECT * FROM foo";
73+
$rs = $pdo->query($sql);
74+
if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) {
75+
// do something
76+
}
77+
} catch (\PDOException $e) {
78+
var_dump($sql);
79+
}
80+
}
81+
82+
/**
83+
* @throws \LogicException|\RuntimeException
84+
*/
85+
public function maybeThrows3(): void
86+
{
87+
if (random_int(0, 1) === 1) {
88+
throw new \RuntimeException();
89+
}
90+
if (random_int(0, 1) === 1) {
91+
throw new \LogicException();
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)