Skip to content

Commit 548287d

Browse files
author
s.duge
committed
- adding test for do while
1 parent a8bafca commit 548287d

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public function process(File $phpcsFile, $stackPtr)
2626
$tokens = $phpcsFile->getTokens();
2727

2828
$startOfConditionPtr = $stackPtr;
29-
if (array_key_exists('scope_opener', $tokens[$startOfConditionPtr])) {
30-
$endPtr = $tokens[$startOfConditionPtr]['scope_opener'] + 1;
31-
} else {
32-
$endPtr = null;
33-
}
29+
$endPtr = $this->getConditionStartPointerDoWhileStable($tokens[$startOfConditionPtr]);
3430

3531
$logicalOperatorTokenIds = [T_BOOLEAN_AND, T_BOOLEAN_OR, T_LOGICAL_AND, T_LOGICAL_OR, T_LOGICAL_XOR];
3632
$scopeOpenerTokenIds = [T_OPEN_CURLY_BRACKET];
@@ -121,4 +117,14 @@ private function checkConditionalOrderForArithmeticExpression(
121117
'ConditionalOrder'
122118
);
123119
}
120+
121+
122+
private function getConditionStartPointerDoWhileStable(array $array): ?int
123+
{
124+
if (array_key_exists('scope_opener', $array)) {
125+
return $array['scope_opener'] + 1;
126+
}
127+
128+
return null;
129+
}
124130
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// @expectedPass
4+
5+
namespace Flyeralarm\CodingGuidelines;
6+
7+
$i = 0;
8+
do {
9+
echo $i;
10+
} while ($i > 0);

0 commit comments

Comments
 (0)