Skip to content

Commit

Permalink
Merge branch 'hotfix/16' into develop
Browse files Browse the repository at this point in the history
Forward port #16
  • Loading branch information
michalbundyra committed May 13, 2019
2 parents 91b61ca + 1af1846 commit 17f3382
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#14](https://github.com/webimpress/coding-standard/pull/14) `PHP\DisallowFqn` - fixes importing FQN
- [#15](https://github.com/webimpress/coding-standard/pull/15) `PHP\DisallowFqn` - fixes importing FQN

- [#16](https://github.com/webimpress/coding-standard/pull/16) `WhiteSpace\ScopeIndent` - fixes code fixer for the case when boolean operator is at the end of the line

## 1.0.2 - 2019-05-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,23 @@ public function process(File $phpcsFile, $stackPtr)
$fix = $phpcsFile->addFixableError($error, $i, 'BooleanOperatorAtTheEnd');

if ($fix) {
$lastNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, $next - 1, null, true);
$string = $phpcsFile->getTokensAsString($i, $lastNonEmpty - $i + 1);
$lastNonEmpty = $i;
while ($tokens[$lastNonEmpty + 1]['line'] === $tokens[$i]['line']) {
++$lastNonEmpty;
}
while (in_array($tokens[$lastNonEmpty]['code'], Tokens::$emptyTokens, true)) {
--$lastNonEmpty;
}

$string = $phpcsFile->getTokensAsString($i, $lastNonEmpty - $i + 1);
if (substr($string, -1) !== '(') {
$string .= ' ';
}

while ($bracket = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, $next - 1, $lastNonEmpty + 1)) {
$next = $bracket;
}

$phpcsFile->fixer->beginChangeset();
$j = $i - 1;
while ($tokens[$j]['code'] === T_WHITESPACE) {
Expand Down
15 changes: 15 additions & 0 deletions test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,18 @@ if ($a
|| ($f && $g))
) {
}

if ($a ||
($b && $c)
) {
}

if ($a || // comment
($b && $c)
) {
}

if ($a ||
((($b && $c)))
) {
}
15 changes: 15 additions & 0 deletions test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,18 @@ if ($a
|| ($f && $g))
) {
}

if ($a
|| ($b && $c)
) {
}

if ($a // comment
|| ($b && $c)
) {
}

if ($a
|| ((($b && $c)))
) {
}
6 changes: 6 additions & 0 deletions test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ protected function getErrorList(string $testFile = '') : array
138 => 1,
146 => 1,
149 => 1,
230 => 1,
231 => 1,
235 => 1,
236 => 1,
240 => 1,
241 => 1,
];
case 'ScopeIndentUnitTest.2.inc':
return [
Expand Down

0 comments on commit 17f3382

Please sign in to comment.