Skip to content

Commit b245bb3

Browse files
committed
Fixed bug #3195 : Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found
1 parent 97f7898 commit b245bb3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
155155
-- Thanks to Juliette Reinders Folmer for the patch
156156
- Fixed bug #3192 : findStartOfStatement doesn't work correctly inside switch
157157
-- Thanks to Vincent Langlet for the patch
158+
- Fixed bug #3195 : Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found
158159
- Fixed bug #3197 : Squiz.NamingConventions.ValidVariableName does not use correct error code for all member vars
159160
- Fixed bug #3219 : Generic.Formatting.MultipleStatementAlignment false positive for empty anonymous classes and closures
160161
- Fixed bug #3258 : Squiz.Formatting.OperatorBracket duplicate error messages for unary minus

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -973,18 +973,38 @@ public function process(File $phpcsFile, $stackPtr)
973973
}
974974

975975
if ($this->tabIndent === true) {
976-
$error .= '%s tabs, found %s';
977-
$data = [
978-
floor($checkIndent / $this->tabWidth),
979-
floor($tokenIndent / $this->tabWidth),
980-
];
976+
$expectedTabs = floor($checkIndent / $this->tabWidth);
977+
$foundTabs = floor($tokenIndent / $this->tabWidth);
978+
$foundSpaces = ($tokenIndent - ($foundTabs * $this->tabWidth));
979+
if ($foundSpaces > 0) {
980+
if ($foundTabs > 0) {
981+
$error .= '%s tabs, found %s tabs and %s spaces';
982+
$data = [
983+
$expectedTabs,
984+
$foundTabs,
985+
$foundSpaces,
986+
];
987+
} else {
988+
$error .= '%s tabs, found %s spaces';
989+
$data = [
990+
$expectedTabs,
991+
$foundSpaces,
992+
];
993+
}
994+
} else {
995+
$error .= '%s tabs, found %s';
996+
$data = [
997+
$expectedTabs,
998+
$foundTabs,
999+
];
1000+
}//end if
9811001
} else {
9821002
$error .= '%s spaces, found %s';
9831003
$data = [
9841004
$checkIndent,
9851005
$tokenIndent,
9861006
];
987-
}
1007+
}//end if
9881008

9891009
if ($this->debug === true) {
9901010
$line = $tokens[$checkToken]['line'];

0 commit comments

Comments
 (0)