Skip to content

Commit 4eb4fc8

Browse files
committed
Squiz/ValidVariableName: don't hide one message behind another
Fixes #1880
1 parent 2503b5a commit 4eb4fc8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,18 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
139139
$errorData[0],
140140
];
141141
$phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
142-
return;
143142
}
144143
} else {
145144
if (substr($varName, 0, 1) !== '_') {
146145
$error = 'Private member variable "%s" must contain a leading underscore';
147146
$phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $errorData);
148-
return;
149147
}
150148
}
151149

152-
if (Common::isCamelCaps($varName, false, $public, false) === false) {
150+
// Remove a potential underscore prefix for testing CamelCaps.
151+
$varName = ltrim($varName, '_');
152+
153+
if (Common::isCamelCaps($varName, false, true, false) === false) {
153154
$error = 'Member variable "%s" is not in valid camel caps format';
154155
$phpcsFile->addError($error, $stackPtr, 'MemberNotCamelCaps', $errorData);
155156
}

src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getErrorList()
5151
67 => 1,
5252
81 => 1,
5353
106 => 1,
54-
107 => 1,
54+
107 => 2,
5555
108 => 1,
5656
117 => 1,
5757
];

0 commit comments

Comments
 (0)