Skip to content

Commit 9ee7171

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

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lint:
3838
--exclude tests/PHPStan/Levels/data/namedArguments.php \
3939
--exclude tests/PHPStan/Rules/Keywords/data/continue-break.php \
4040
--exclude tests/PHPStan/Rules/Keywords/data/continue-break-property-hook.php \
41+
--exclude tests/PHPStan/Rules/Keywords/data/bug-13790.php \
4142
--exclude tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php \
4243
--exclude tests/PHPStan/Rules/Properties/data/properties-in-interface.php \
4344
--exclude tests/PHPStan/Rules/Properties/data/read-only-property.php \

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)