Skip to content

Commit

Permalink
Generic.WhiteSpace.ScopeIndent now disables exact indent checking for…
Browse files Browse the repository at this point in the history
… multi-line chained methods (ref #2371)
  • Loading branch information
pfrenssen committed Jan 18, 2019
1 parent cbe9b4e commit 6e315f1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,15 @@ public function process(File $phpcsFile, $stackPtr)
$exact = true;
}

// Don't perform strict checking on chained method calls since they
// are often covered by custom rules.
if ($checkToken !== null
&& $tokens[$checkToken]['code'] === T_OBJECT_OPERATOR
&& $exact === true
) {
$exact = false;
}

if ($checkIndent === null) {
$checkIndent = $currentIndent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ function foo() {
if ($foo) {
echo 'baz';
}
$this->foo()
->bar()
->baz();
}
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ function foo() {
if ($foo) {
echo 'baz';
}
$this->foo()
->bar()
->baz();
}
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ function foo() {
if ($foo) {
echo 'baz';
}
$this->foo()
->bar()
->baz();
}
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ function foo() {
if ($foo) {
echo 'baz';
}
$this->foo()
->bar()
->baz();
}
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

Expand Down
17 changes: 9 additions & 8 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,21 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1293 => 1,
1310 => 1,
1312 => 1,
1327 => 1,
1328 => 1,
1329 => 1,
1315 => 1,
1330 => 1,
1331 => 1,
1332 => 1,
1333 => 1,
1334 => 1,
1335 => 1,
1340 => 1,
1342 => 1,
1338 => 1,
1343 => 1,
1345 => 1,
1364 => 1,
1365 => 1,
1366 => 1,
1348 => 1,
1367 => 1,
1368 => 1,
1369 => 1,
1370 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 6e315f1

Please sign in to comment.