Browse Source

clean ups

SpacePossum 3 years ago
parent
commit
923af7bc30

+ 1 - 3
src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php

@@ -81,9 +81,7 @@ final class NativeFunctionTypeDeclarationCasingFixer extends AbstractFixer
             ]
         );
 
-        if (\PHP_VERSION_ID >= 70200) {
-            $this->hints = array_merge($this->hints, ['object' => true]);
-        }
+        $this->hints = array_merge($this->hints, ['object' => true]);
 
         if (\PHP_VERSION_ID >= 80000) {
             $this->hints = array_merge($this->hints, ['static' => true]);

+ 1 - 2
src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php

@@ -147,8 +147,6 @@ SAMPLE
         $fixArguments = \in_array(self::ELEMENTS_ARGUMENTS, $this->configuration['elements'], true);
         $fixParameters = \in_array(self::ELEMENTS_PARAMETERS, $this->configuration['elements'], true);
 
-        $tokensAnalyzer = new TokensAnalyzer($tokens);
-
         for ($index = $tokens->count() - 1; $index >= 0; --$index) {
             $prevIndex = $tokens->getPrevMeaningfulToken($index);
 
@@ -194,6 +192,7 @@ SAMPLE
     private function fixBlock(Tokens $tokens, int $startIndex): void
     {
         $tokensAnalyzer = new TokensAnalyzer($tokens);
+
         if (!$tokensAnalyzer->isBlockMultiline($tokens, $startIndex)) {
             return;
         }

+ 1 - 1
src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php

@@ -310,7 +310,7 @@ final class LambdaNotUsedImportFixer extends AbstractFixer
 
     private function clearImports(Tokens $tokens, array $imports): void
     {
-        foreach ($imports as $content => $removeIndex) {
+        foreach ($imports as $removeIndex) {
             $tokens->clearTokenAndMergeSurroundingWhitespace($removeIndex);
             $previousRemoveIndex = $tokens->getPrevMeaningfulToken($removeIndex);
 

+ 1 - 1
src/Fixer/Operator/TernaryOperatorSpacesFixer.php

@@ -170,7 +170,7 @@ final class TernaryOperatorSpacesFixer extends AbstractFixer
     {
         if ($tokens[$index]->isWhitespace()) {
             if (
-                  !str_contains($tokens[$index]->getContent(), "\n")
+                !str_contains($tokens[$index]->getContent(), "\n")
                 && !$tokens[$index - 1]->isComment()
             ) {
                 $tokens[$index] = new Token([T_WHITESPACE, ' ']);

+ 1 - 6
src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php

@@ -154,7 +154,7 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
         $functionNameIndex = $tokens->getNextMeaningfulToken($index);
         $functionName = $tokens[$functionNameIndex]->getContent();
 
-        if ($this->startsWith('test', $functionName)) {
+        if (str_starts_with($functionName, 'test')) {
             return true;
         }
 
@@ -173,11 +173,6 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
         return $tokens[$index]->isGivenKind(T_FUNCTION) && !$tokensAnalyzer->isLambda($index);
     }
 
-    private function startsWith(string $needle, string $haystack): bool
-    {
-        return substr($haystack, 0, \strlen($needle)) === $needle;
-    }
-
     private function updateDocBlock(Tokens $tokens, int $docBlockIndex): void
     {
         $doc = new DocBlock($tokens[$docBlockIndex]->getContent());

+ 4 - 2
src/Fixer/Phpdoc/PhpdocIndentFixer.php

@@ -96,13 +96,15 @@ class DocBlocks
                 continue;
             }
 
-            $indent = '';
             if ($tokens[$nextIndex - 1]->isWhitespace()) {
                 $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$nextIndex - 1]);
+            } else {
+                $indent = '';
             }
 
             $newPrevContent = $this->fixWhitespaceBeforeDocblock($prevToken->getContent(), $indent);
-            if ($newPrevContent) {
+
+            if ('' !== $newPrevContent) {
                 if ($prevToken->isArray()) {
                     $tokens[$prevIndex] = new Token([$prevToken->getId(), $newPrevContent]);
                 } else {

+ 2 - 2
src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php

@@ -93,7 +93,7 @@ function foo() {}
             }
 
             foreach ($annotations as $annotation) {
-                $this->fixAnnotation($doc, $annotation);
+                $this->fixAnnotation($annotation);
             }
 
             $newContent = $doc->getContent();
@@ -115,7 +115,7 @@ function foo() {}
     /**
      * Remove `return void` or `return null` annotations.
      */
-    private function fixAnnotation(DocBlock $doc, Annotation $annotation): void
+    private function fixAnnotation(Annotation $annotation): void
     {
         $types = $annotation->getNormalizedTypes();
 

+ 1 - 1
src/Fixer/Phpdoc/PhpdocOrderFixer.php

@@ -85,7 +85,7 @@ final class PhpdocOrderFixer extends AbstractFixer
             // move param to start, return to end, leave throws in the middle
             $content = $this->moveParamAnnotations($content);
             // we're parsing the content again to make sure the internal
-            // state of the dockblock is correct after the modifications
+            // state of the docblock is correct after the modifications
             $content = $this->moveReturnAnnotations($content);
             // persist the content at the end
             $tokens[$index] = new Token([T_DOC_COMMENT, $content]);

+ 1 - 1
src/Fixer/Phpdoc/PhpdocTypesFixer.php

@@ -90,7 +90,7 @@ final class PhpdocTypesFixer extends AbstractPhpdocTypesFixer implements Configu
             implode(
                 '|',
                 array_map(
-                    function (string $type): string {
+                    static function (string $type): string {
                         return preg_quote($type, '/');
                     },
                     $typesToFix

+ 2 - 2
src/Tokenizer/Tokens.php

@@ -1165,8 +1165,8 @@ class Tokens extends \SplFixedArray
             $tokenToCheck = $this[$whitespaceIndex];
 
             // if the token candidate to remove is preceded by single line comment we do not consider the new line after this comment as part of T_WHITESPACE
-            if (isset($this[$whitespaceIndex - 1]) && $this[$whitespaceIndex - 1]->isComment() && '/*' !== substr($this[$whitespaceIndex - 1]->getContent(), 0, 2)) {
-                [$emptyString, $newContent, $whitespacesToCheck] = Preg::split('/^(\R)/', $this[$whitespaceIndex]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);
+            if (isset($this[$whitespaceIndex - 1]) && $this[$whitespaceIndex - 1]->isComment() && !str_starts_with($this[$whitespaceIndex - 1]->getContent(), '/*')) {
+                [, $newContent, $whitespacesToCheck] = Preg::split('/^(\R)/', $this[$whitespaceIndex]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);
 
                 if ('' === $whitespacesToCheck) {
                     return;

Some files were not shown because too many files changed in this diff