Skip to content

Commit d140424

Browse files
authored
CS/QA: remove unused variables (#446)
* test(phcs): Check for unused variables in PHPCS it self * Manually fixed all unused varaibles * Revert Slevomat dependency * Revert array_keys changes * revert changes that should stay
1 parent aca6b8b commit d140424

20 files changed

+27
-43
lines changed

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ public static function setConfigData($key, $value, $temp=false)
15701570
// standards paths are added to the autoloader.
15711571
if ($key === 'installed_paths') {
15721572
$installedStandards = Standards::getInstalledStandardDetails();
1573-
foreach ($installedStandards as $name => $details) {
1573+
foreach ($installedStandards as $details) {
15741574
Autoload::addSearchPath($details['path'], $details['namespace']);
15751575
}
15761576
}

src/Filters/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function shouldProcessFile($path)
179179
// complete extension list and make sure one is allowed.
180180
$extensions = [];
181181
array_shift($fileParts);
182-
foreach ($fileParts as $part) {
182+
while (empty($fileParts) === false) {
183183
$extensions[implode('.', $fileParts)] = 1;
184184
array_shift($fileParts);
185185
}

src/Runner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ public function init()
333333

334334
// Create this class so it is autoloaded and sets up a bunch
335335
// of PHP_CodeSniffer-specific token type constants.
336-
$tokens = new Tokens();
336+
new Tokens();
337337

338338
// Allow autoloading of custom files inside installed standards.
339339
$installedStandards = Standards::getInstalledStandardDetails();
340-
foreach ($installedStandards as $name => $details) {
340+
foreach ($installedStandards as $details) {
341341
Autoload::addSearchPath($details['path'], $details['namespace']);
342342
}
343343

src/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr)
5454
{
5555
// Allow a byte-order mark.
5656
$tokens = $phpcsFile->getTokens();
57-
foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
57+
foreach ($this->bomDefinitions as $expectedBomHex) {
5858
$bomByteLength = (strlen($expectedBomHex) / 2);
5959
$htmlBomHex = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength));
6060
if ($htmlBomHex === $expectedBomHex && strlen($tokens[0]['content']) === $bomByteLength) {

src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
5656
if ($stackPtr > 0) {
5757
// Allow a byte-order mark.
5858
$tokens = $phpcsFile->getTokens();
59-
foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
59+
foreach ($this->bomDefinitions as $expectedBomHex) {
6060
$bomByteLength = (strlen($expectedBomHex) / 2);
6161
$htmlBomHex = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength));
6262
if ($htmlBomHex === $expectedBomHex) {

src/Standards/Generic/Tests/Debug/JSHintUnitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ final class JSHintUnitTest extends AbstractSniffUnitTest
2828
*/
2929
protected function shouldSkipTest()
3030
{
31-
$rhinoPath = Config::getExecutablePath('rhino');
3231
$jshintPath = Config::getExecutablePath('jshint');
3332
if ($jshintPath === null) {
3433
return true;

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
8686
// Check return type (can be multiple, separated by '|').
8787
$typeNames = explode('|', $returnType);
8888
$suggestedNames = [];
89-
foreach ($typeNames as $i => $typeName) {
89+
foreach ($typeNames as $typeName) {
9090
$suggestedName = Common::suggestType($typeName);
9191
if (in_array($suggestedName, $suggestedNames, true) === false) {
9292
$suggestedNames[] = $suggestedName;

src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
135135
// Check var type (can be multiple, separated by '|').
136136
$typeNames = explode('|', $varType);
137137
$suggestedNames = [];
138-
foreach ($typeNames as $i => $typeName) {
138+
foreach ($typeNames as $typeName) {
139139
$suggestedName = Common::suggestType($typeName);
140140
if (in_array($suggestedName, $suggestedNames, true) === false) {
141141
$suggestedNames[] = $suggestedName;

src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public function processBracket($phpcsFile, $openBracket, $tokens, $type='functio
225225
}//end if
226226

227227
// Each line between the brackets should contain a single parameter.
228-
$lastComma = null;
229228
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
230229
// Skip brackets, like arrays, as they can contain commas.
231230
if (isset($tokens[$i]['bracket_opener']) === true) {

src/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,18 @@ public function process(File $phpcsFile, $stackPtr)
238238
];
239239
$emptyTokens += Tokens::$phpcsCommentTokens;
240240

241-
$numComment = 0;
242-
$numPossible = 0;
243241
$numCode = 0;
244242
$numNonWhitespace = 0;
245243

246244
for ($i = 0; $i < $numTokens; $i++) {
247-
if (isset($emptyTokens[$stringTokens[$i]['code']]) === true) {
248-
// Looks like comment.
249-
$numComment++;
250-
} else if (isset(Tokens::$comparisonTokens[$stringTokens[$i]['code']]) === true
251-
|| isset(Tokens::$arithmeticTokens[$stringTokens[$i]['code']]) === true
252-
|| $stringTokens[$i]['code'] === T_GOTO_LABEL
253-
) {
245+
// Do not count comments.
246+
if (isset($emptyTokens[$stringTokens[$i]['code']]) === false
254247
// Commented out HTML/XML and other docs contain a lot of these
255248
// characters, so it is best to not use them directly.
256-
$numPossible++;
257-
} else {
249+
&& isset(Tokens::$comparisonTokens[$stringTokens[$i]['code']]) === false
250+
&& isset(Tokens::$arithmeticTokens[$stringTokens[$i]['code']]) === false
251+
&& $stringTokens[$i]['code'] !== T_GOTO_LABEL
252+
) {
258253
// Looks like code.
259254
$numCode++;
260255
}

0 commit comments

Comments
 (0)