diff --git a/src/Config.php b/src/Config.php index 7f6e12e7af..61addd915e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1570,7 +1570,7 @@ public static function setConfigData($key, $value, $temp=false) // standards paths are added to the autoloader. if ($key === 'installed_paths') { $installedStandards = Standards::getInstalledStandardDetails(); - foreach ($installedStandards as $name => $details) { + foreach ($installedStandards as $details) { Autoload::addSearchPath($details['path'], $details['namespace']); } } diff --git a/src/Filters/Filter.php b/src/Filters/Filter.php index 349fd6dbce..8376d15c3b 100644 --- a/src/Filters/Filter.php +++ b/src/Filters/Filter.php @@ -179,7 +179,7 @@ protected function shouldProcessFile($path) // complete extension list and make sure one is allowed. $extensions = []; array_shift($fileParts); - foreach ($fileParts as $part) { + while (empty($fileParts) === false) { $extensions[implode('.', $fileParts)] = 1; array_shift($fileParts); } diff --git a/src/Runner.php b/src/Runner.php index b5afa71d05..cfd844732f 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -333,11 +333,11 @@ public function init() // Create this class so it is autoloaded and sets up a bunch // of PHP_CodeSniffer-specific token type constants. - $tokens = new Tokens(); + new Tokens(); // Allow autoloading of custom files inside installed standards. $installedStandards = Standards::getInstalledStandardDetails(); - foreach ($installedStandards as $name => $details) { + foreach ($installedStandards as $details) { Autoload::addSearchPath($details['path'], $details['namespace']); } diff --git a/src/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php b/src/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php index 1d79a0ea76..d90b893016 100644 --- a/src/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php +++ b/src/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php @@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr) { // Allow a byte-order mark. $tokens = $phpcsFile->getTokens(); - foreach ($this->bomDefinitions as $bomName => $expectedBomHex) { + foreach ($this->bomDefinitions as $expectedBomHex) { $bomByteLength = (strlen($expectedBomHex) / 2); $htmlBomHex = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength)); if ($htmlBomHex === $expectedBomHex && strlen($tokens[0]['content']) === $bomByteLength) { diff --git a/src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php b/src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php index 66f73860ed..61ff4f2f0e 100644 --- a/src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php +++ b/src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php @@ -56,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr) if ($stackPtr > 0) { // Allow a byte-order mark. $tokens = $phpcsFile->getTokens(); - foreach ($this->bomDefinitions as $bomName => $expectedBomHex) { + foreach ($this->bomDefinitions as $expectedBomHex) { $bomByteLength = (strlen($expectedBomHex) / 2); $htmlBomHex = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength)); if ($htmlBomHex === $expectedBomHex) { diff --git a/src/Standards/Generic/Tests/Debug/JSHintUnitTest.php b/src/Standards/Generic/Tests/Debug/JSHintUnitTest.php index 19c0473a87..2545159945 100644 --- a/src/Standards/Generic/Tests/Debug/JSHintUnitTest.php +++ b/src/Standards/Generic/Tests/Debug/JSHintUnitTest.php @@ -28,7 +28,6 @@ final class JSHintUnitTest extends AbstractSniffUnitTest */ protected function shouldSkipTest() { - $rhinoPath = Config::getExecutablePath('rhino'); $jshintPath = Config::getExecutablePath('jshint'); if ($jshintPath === null) { return true; diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index 672818337c..b0b7cafb32 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -86,7 +86,7 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart) // Check return type (can be multiple, separated by '|'). $typeNames = explode('|', $returnType); $suggestedNames = []; - foreach ($typeNames as $i => $typeName) { + foreach ($typeNames as $typeName) { $suggestedName = Common::suggestType($typeName); if (in_array($suggestedName, $suggestedNames, true) === false) { $suggestedNames[] = $suggestedName; diff --git a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php index 76fbc6dca6..61ccbf7a0b 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php @@ -135,7 +135,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) // Check var type (can be multiple, separated by '|'). $typeNames = explode('|', $varType); $suggestedNames = []; - foreach ($typeNames as $i => $typeName) { + foreach ($typeNames as $typeName) { $suggestedName = Common::suggestType($typeName); if (in_array($suggestedName, $suggestedNames, true) === false) { $suggestedNames[] = $suggestedName; diff --git a/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php b/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php index 626b330f11..61d23ce286 100644 --- a/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php +++ b/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php @@ -225,7 +225,6 @@ public function processBracket($phpcsFile, $openBracket, $tokens, $type='functio }//end if // Each line between the brackets should contain a single parameter. - $lastComma = null; for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { // Skip brackets, like arrays, as they can contain commas. if (isset($tokens[$i]['bracket_opener']) === true) { diff --git a/src/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php b/src/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php index 59e91f07c8..c8e1a40303 100644 --- a/src/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php +++ b/src/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php @@ -238,23 +238,18 @@ public function process(File $phpcsFile, $stackPtr) ]; $emptyTokens += Tokens::$phpcsCommentTokens; - $numComment = 0; - $numPossible = 0; $numCode = 0; $numNonWhitespace = 0; for ($i = 0; $i < $numTokens; $i++) { - if (isset($emptyTokens[$stringTokens[$i]['code']]) === true) { - // Looks like comment. - $numComment++; - } else if (isset(Tokens::$comparisonTokens[$stringTokens[$i]['code']]) === true - || isset(Tokens::$arithmeticTokens[$stringTokens[$i]['code']]) === true - || $stringTokens[$i]['code'] === T_GOTO_LABEL - ) { + // Do not count comments. + if (isset($emptyTokens[$stringTokens[$i]['code']]) === false // Commented out HTML/XML and other docs contain a lot of these // characters, so it is best to not use them directly. - $numPossible++; - } else { + && isset(Tokens::$comparisonTokens[$stringTokens[$i]['code']]) === false + && isset(Tokens::$arithmeticTokens[$stringTokens[$i]['code']]) === false + && $stringTokens[$i]['code'] !== T_GOTO_LABEL + ) { // Looks like code. $numCode++; } diff --git a/src/Tokenizers/JS.php b/src/Tokenizers/JS.php index 3d1162eb32..c7249fcd93 100644 --- a/src/Tokenizers/JS.php +++ b/src/Tokenizers/JS.php @@ -1188,7 +1188,7 @@ public function processAdditional() } } } else if ($this->tokens[$i]['code'] === T_CLOSE_OBJECT) { - $opener = array_pop($classStack); + array_pop($classStack); } else if ($this->tokens[$i]['code'] === T_COLON) { // If it is a scope opener, it belongs to a // DEFAULT or CASE statement. diff --git a/tests/Core/File/GetMemberPropertiesTest.php b/tests/Core/File/GetMemberPropertiesTest.php index e100b76206..2d5fbe6346 100644 --- a/tests/Core/File/GetMemberPropertiesTest.php +++ b/tests/Core/File/GetMemberPropertiesTest.php @@ -1146,7 +1146,7 @@ public function testNotClassPropertyException($identifier) $this->expectRunTimeException('$stackPtr is not a class member var'); $variable = $this->getTargetToken($identifier, T_VARIABLE); - $result = self::$phpcsFile->getMemberProperties($variable); + self::$phpcsFile->getMemberProperties($variable); }//end testNotClassPropertyException() @@ -1182,8 +1182,8 @@ public function testNotAVariableException() { $this->expectRunTimeException('$stackPtr must be of type T_VARIABLE'); - $next = $this->getTargetToken('/* testNotAVariable */', T_RETURN); - $result = self::$phpcsFile->getMemberProperties($next); + $next = $this->getTargetToken('/* testNotAVariable */', T_RETURN); + self::$phpcsFile->getMemberProperties($next); }//end testNotAVariableException() diff --git a/tests/Core/Ruleset/ExplainTest.php b/tests/Core/Ruleset/ExplainTest.php index fc84f88ac7..5438c65cfc 100644 --- a/tests/Core/Ruleset/ExplainTest.php +++ b/tests/Core/Ruleset/ExplainTest.php @@ -249,8 +249,8 @@ public function testExplainWillExplainEachStandardSeparately() $this->expectOutputString($expected); - $runner = new Runner(); - $exitCode = $runner->runPHPCS(); + $runner = new Runner(); + $runner->runPHPCS(); }//end testExplainWillExplainEachStandardSeparately() diff --git a/tests/Core/Ruleset/RuleInclusionTest.php b/tests/Core/Ruleset/RuleInclusionTest.php index 039c99748d..ef3ad83cac 100644 --- a/tests/Core/Ruleset/RuleInclusionTest.php +++ b/tests/Core/Ruleset/RuleInclusionTest.php @@ -439,8 +439,6 @@ public function testSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFail { $this->assertArrayHasKey($sniffClass, self::$ruleset->sniffs, 'Sniff class '.$sniffClass.' not listed in registered sniffs'); - $sniffObject = self::$ruleset->sniffs[$sniffClass]; - $hasProperty = (new ReflectionObject(self::$ruleset->sniffs[$sniffClass]))->hasProperty($propertyName); $errorMsg = sprintf('Property %s registered for sniff %s which does not support it', $propertyName, $sniffClass); $this->assertFalse($hasProperty, $errorMsg); diff --git a/tests/Core/Ruleset/SetSniffPropertyTest.php b/tests/Core/Ruleset/SetSniffPropertyTest.php index 5b02278741..36e6f0097b 100644 --- a/tests/Core/Ruleset/SetSniffPropertyTest.php +++ b/tests/Core/Ruleset/SetSniffPropertyTest.php @@ -148,7 +148,7 @@ public function testSetPropertyThrowsErrorOnInvalidProperty() // Set up the ruleset. $standard = __DIR__.'/SetPropertyThrowsErrorOnInvalidPropertyTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); + new Ruleset($config); }//end testSetPropertyThrowsErrorOnInvalidProperty() @@ -175,7 +175,7 @@ public function testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute() // Set up the ruleset. $standard = __DIR__.'/SetPropertyNotAllowedViaAttributeTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); + new Ruleset($config); }//end testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute() @@ -193,7 +193,7 @@ public function testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStand // Set up the ruleset. $standard = __DIR__.'/SetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandardTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); + new Ruleset($config); }//end testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandard() @@ -211,7 +211,7 @@ public function testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCateg // Set up the ruleset. $standard = __DIR__.'/SetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategoryTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); + new Ruleset($config); }//end testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory() @@ -383,7 +383,6 @@ public function testDirectCallWithOldArrayFormatThrowsDeprecationNotice() } $name = 'AllowedAsDeclared'; - $sniffCode = "Fixtures.SetProperty.{$name}"; $sniffClass = 'Fixtures\Sniffs\SetProperty\\'.$name.'Sniff'; // Set up the ruleset. @@ -391,8 +390,6 @@ public function testDirectCallWithOldArrayFormatThrowsDeprecationNotice() $config = new ConfigDouble(["--standard=$standard"]); $ruleset = new Ruleset($config); - $propertyName = 'arbitrarystring'; - $ruleset->setSniffProperty( $sniffClass, 'arbitrarystring', diff --git a/tests/Core/Tokenizer/PHP/BackfillFnTokenTest.php b/tests/Core/Tokenizer/PHP/BackfillFnTokenTest.php index 2632337a5c..f268bedd8c 100644 --- a/tests/Core/Tokenizer/PHP/BackfillFnTokenTest.php +++ b/tests/Core/Tokenizer/PHP/BackfillFnTokenTest.php @@ -658,8 +658,6 @@ public function testTernary() */ public function testTernaryWithTypes() { - $tokens = $this->phpcsFile->getTokens(); - $token = $this->getTargetToken('/* testTernaryWithTypes */', T_FN); $this->backfillHelper($token); $this->scopePositionTestHelper($token, 15, 27); diff --git a/tests/Core/Tokenizer/PHP/StableCommentWhitespaceTest.php b/tests/Core/Tokenizer/PHP/StableCommentWhitespaceTest.php index 6a58ccbbd7..ec287745f2 100644 --- a/tests/Core/Tokenizer/PHP/StableCommentWhitespaceTest.php +++ b/tests/Core/Tokenizer/PHP/StableCommentWhitespaceTest.php @@ -38,7 +38,7 @@ public function testCommentTokenization($testMarker, $expectedTokens) $tokens = $this->phpcsFile->getTokens(); $comment = $this->getTargetToken($testMarker, Tokens::$commentTokens); - foreach ($expectedTokens as $key => $tokenInfo) { + foreach ($expectedTokens as $tokenInfo) { $this->assertSame( constant($tokenInfo['type']), $tokens[$comment]['code'], diff --git a/tests/Core/Tokenizer/PHP/StableCommentWhitespaceWinTest.php b/tests/Core/Tokenizer/PHP/StableCommentWhitespaceWinTest.php index dbb103060a..989bcd0f47 100644 --- a/tests/Core/Tokenizer/PHP/StableCommentWhitespaceWinTest.php +++ b/tests/Core/Tokenizer/PHP/StableCommentWhitespaceWinTest.php @@ -35,7 +35,7 @@ public function testCommentTokenization($testMarker, $expectedTokens) $tokens = $this->phpcsFile->getTokens(); $comment = $this->getTargetToken($testMarker, Tokens::$commentTokens); - foreach ($expectedTokens as $key => $tokenInfo) { + foreach ($expectedTokens as $tokenInfo) { $this->assertSame( constant($tokenInfo['type']), $tokens[$comment]['code'], diff --git a/tests/Core/Tokenizer/PHP/UndoNamespacedNameSingleTokenTest.php b/tests/Core/Tokenizer/PHP/UndoNamespacedNameSingleTokenTest.php index 18e2275768..6decc164fe 100644 --- a/tests/Core/Tokenizer/PHP/UndoNamespacedNameSingleTokenTest.php +++ b/tests/Core/Tokenizer/PHP/UndoNamespacedNameSingleTokenTest.php @@ -42,7 +42,7 @@ public function testIdentifierTokenization($testMarker, $expectedTokens) $tokens = $this->phpcsFile->getTokens(); $identifier = $this->getTargetToken($testMarker, constant($expectedTokens[0]['type'])); - foreach ($expectedTokens as $key => $tokenInfo) { + foreach ($expectedTokens as $tokenInfo) { $this->assertSame( constant($tokenInfo['type']), $tokens[$identifier]['code'], diff --git a/tests/Standards/AllSniffs.php b/tests/Standards/AllSniffs.php index 8644ca39e3..1e273e28eb 100644 --- a/tests/Standards/AllSniffs.php +++ b/tests/Standards/AllSniffs.php @@ -48,8 +48,6 @@ public static function suite() $suite = new TestSuite('PHP CodeSniffer Standards'); - $isInstalled = !is_file(__DIR__.'/../../autoload.php'); - // Optionally allow for ignoring the tests for one or more standards. $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); if ($ignoreTestsForStandards === false) {