Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ lint:
--exclude tests/PHPStan/Levels/data/namedArguments.php \
--exclude tests/PHPStan/Rules/Keywords/data/continue-break.php \
--exclude tests/PHPStan/Rules/Keywords/data/continue-break-property-hook.php \
--exclude tests/PHPStan/Rules/Keywords/data/bug-13790-break.php \
--exclude tests/PHPStan/Rules/Keywords/data/bug-13790-continue.php \
--exclude tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php \
--exclude tests/PHPStan/Rules/Properties/data/properties-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/read-only-property.php \
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Keywords/ContinueBreakInLoopRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
$value = $node->num->value;
}

$parentStmtTypes = array_reverse($node->getAttribute(ParentStmtTypesVisitor::ATTRIBUTE_NAME));
$parentStmtTypes = array_reverse($node->getAttribute(ParentStmtTypesVisitor::ATTRIBUTE_NAME, []));
foreach ($parentStmtTypes as $parentStmtType) {
if ($parentStmtType === Stmt\Case_::class) {
continue;
Expand Down
20 changes: 20 additions & 0 deletions tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,24 @@ public function testPropertyHooks(): void
]);
}

public function testBug13790(): void
{
$this->analyse(
[
__DIR__ . '/data/bug-13790-break.php',
__DIR__ . '/data/bug-13790-continue.php',
],
[
[
'Keyword break used outside of a loop or a switch statement.',
2,
],
[
'Keyword continue used outside of a loop or a switch statement.',
2,
],
],
);
}

}
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/Keywords/data/bug-13790-break.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
break;
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/Keywords/data/bug-13790-continue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
continue;
Loading