Skip to content

Commit

Permalink
Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakInden…
Browse files Browse the repository at this point in the history
…t false positive when case keyword is not indented
  • Loading branch information
gsherwood committed Nov 3, 2020
1 parent 75a0512 commit 99b0339
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed an issue that could occurr when checking files on network drives, such as with WSL2 on Windows 10
-- This works around a long-standing PHP bug with is_readable()
-- Thanks to Michael S for the patch
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
</notes>
<contents>
<dir name="/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->replaceToken($nextCloser, trim($tokens[$nextCloser]['content']));
}
} else {
$diff = ($caseAlignment + $this->indent - $tokens[$nextCloser]['column']);
$diff = ($tokens[$nextCase]['column'] + $this->indent - $tokens[$nextCloser]['column']);
if ($diff !== 0) {
$error = 'Terminating statement must be indented to the same level as the CASE body';
$fix = $phpcsFile->addFixableError($error, $nextCloser, 'BreakIndent');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,13 @@ $foo = $foo ?
}
} :
null;

switch ($foo) {
case Foo::INTERFACE:
echo '1';
return self::INTERFACE;
case Foo::TRAIT:
case Foo::ARRAY:
echo '1';
return self::VALUE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,13 @@ $foo = $foo ?
}
} :
null;

switch ($foo) {
case Foo::INTERFACE:
echo '1';
return self::INTERFACE;
case Foo::TRAIT:
case Foo::ARRAY:
echo '1';
return self::VALUE;
}

0 comments on commit 99b0339

Please sign in to comment.