Skip to content

Commit b16240c

Browse files
committed
add default value for getAttribute call in ContinueBreakInLoopRule
1 parent 013e021 commit b16240c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Rules/Keywords/ContinueBreakInLoopRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3737
$value = $node->num->value;
3838
}
3939

40-
$parentStmtTypes = array_reverse($node->getAttribute(ParentStmtTypesVisitor::ATTRIBUTE_NAME));
40+
$parentStmtTypes = array_reverse($node->getAttribute(ParentStmtTypesVisitor::ATTRIBUTE_NAME, []));
4141
foreach ($parentStmtTypes as $parentStmtType) {
4242
if ($parentStmtType === Stmt\Case_::class) {
4343
continue;

tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ public function testPropertyHooks(): void
7474
]);
7575
}
7676

77+
public function testBug13790(): void
78+
{
79+
$this->analyse([__DIR__ . '/data/bug-13790.php'], [
80+
[
81+
'Keyword break used outside of a loop or a switch statement.',
82+
2,
83+
],
84+
]);
85+
}
86+
7787
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
break;

0 commit comments

Comments
 (0)