From d0f7f42d3ebf25c911a0de24e52afc24644c5ca4 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 13 May 2019 17:40:43 +0100 Subject: [PATCH 1/3] Fixed changelog entry #15 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eddcfe64..fd2b1b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ 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 ## 1.0.2 - 2019-05-12 From fd083d2f8a21229f9388f46b7a0b2e69584723e4 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 13 May 2019 19:42:24 +0100 Subject: [PATCH 2/3] Hotfix ScopeIndent sniff - boolean operator at the end of the line --- .../Sniffs/WhiteSpace/ScopeIndentSniff.php | 14 ++++++++++++-- test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc | 15 +++++++++++++++ .../WhiteSpace/ScopeIndentUnitTest.1.inc.fixed | 15 +++++++++++++++ test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php | 6 ++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/WebimpressCodingStandard/Sniffs/WhiteSpace/ScopeIndentSniff.php b/src/WebimpressCodingStandard/Sniffs/WhiteSpace/ScopeIndentSniff.php index 36bc0edd..4b1c1b7c 100644 --- a/src/WebimpressCodingStandard/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -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) { diff --git a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc index de2e3388..c705f43e 100644 --- a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc +++ b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc @@ -226,3 +226,18 @@ if ($a || ($f && $g)) ) { } + +if ($a || + ($b && $c) +) { +} + +if ($a || // comment + ($b && $c) +) { +} + +if ($a || + ((($b && $c))) +) { +} diff --git a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed index 429cc2b0..c064569c 100644 --- a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed +++ b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed @@ -220,3 +220,18 @@ if ($a || ($f && $g)) ) { } + +if ($a + || ($b && $c) +) { +} + +if ($a // comment + || ($b && $c) +) { +} + +if ($a + || ((($b && $c))) +) { +} diff --git a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php index 3f2576ec..fbd4e2e2 100644 --- a/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php +++ b/test/Sniffs/WhiteSpace/ScopeIndentUnitTest.php @@ -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 [ From 1af18460dbcf86a8397d8fa013420e6d1fb79ac5 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 13 May 2019 19:55:53 +0100 Subject: [PATCH 3/3] Adds CHANGELOG entry for #16 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd2b1b89..dff6bd89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ All notable changes to this project will be documented in this file, in reverse - [#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 ### Added