Browse Source

Tree shake PHP8.1 PRs

SpacePossum 3 years ago
parent
commit
0b64c2a5cf

+ 4 - 5
src/AbstractPhpdocTypesFixer.php

@@ -120,10 +120,9 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
      */
     private function normalizeType(string $type): string
     {
-        if ('[]' === substr($type, -2)) {
-            return $this->normalizeType(substr($type, 0, -2)).'[]';
-        }
-
-        return $this->normalize($type);
+        return str_ends_with($type, '[]')
+            ? $this->normalizeType(substr($type, 0, -2)).'[]'
+            : $this->normalize($type)
+        ;
     }
 }

+ 2 - 2
src/DocBlock/DocBlock.php

@@ -253,9 +253,9 @@ final class DocBlock
         $lineString = str_replace('*/', '', $lineString);
         $lineString = trim($lineString);
 
-        if ('/**' === substr($lineString, 0, 3)) {
+        if (str_starts_with($lineString, '/**')) {
             $lineString = substr($lineString, 3);
-        } elseif ('*' === substr($lineString, 0, 1)) {
+        } elseif (str_starts_with($lineString, '*')) {
             $lineString = substr($lineString, 1);
         }
 

+ 1 - 1
src/Fixer/ArrayNotation/TrimArraySpacesFixer.php

@@ -88,7 +88,7 @@ final class TrimArraySpacesFixer extends AbstractFixer
                 !$nextNonWhitespaceToken->isComment()
                 || $nextNonWhitespaceIndex === $prevNonWhitespaceIndex
                 || $tokenAfterNextNonWhitespaceToken->isWhitespace(" \t")
-                || '/*' === substr($nextNonWhitespaceToken->getContent(), 0, 2)
+                || str_starts_with($nextNonWhitespaceToken->getContent(), '/*')
             )
         ) {
             $tokens->clearAt($nextIndex);

+ 2 - 1
src/Fixer/Casing/MagicMethodCasingFixer.php

@@ -113,7 +113,8 @@ $foo->__INVOKE(1);
             }
 
             $content = $tokens[$index]->getContent();
-            if ('__' !== substr($content, 0, 2)) {
+
+            if (!str_starts_with($content, '__')) {
                 continue; // cheap look ahead
             }
 

+ 2 - 2
src/Fixer/ClassNotation/ClassDefinitionFixer.php

@@ -330,10 +330,10 @@ $foo = new class(){};
                 if ($tokens[$i - 1]->isComment() || $tokens[$i + 1]->isComment()) {
                     $content = $tokens[$i - 1]->getContent();
 
-                    if (!('#' === $content || '//' === substr($content, 0, 2))) {
+                    if (!('#' === $content || str_starts_with($content, '//'))) {
                         $content = $tokens[$i + 1]->getContent();
 
-                        if (!('#' === $content || '//' === substr($content, 0, 2))) {
+                        if (!('#' === $content || str_starts_with($content, '//'))) {
                             $tokens[$i] = new Token([T_WHITESPACE, ' ']);
                         }
                     }

+ 4 - 5
src/Fixer/ClassNotation/OrderedClassElementsFixer.php

@@ -401,11 +401,10 @@ class Example
             return ['phpunit', strtolower($nameToken->getContent())];
         }
 
-        if ('__' === substr($nameToken->getContent(), 0, 2)) {
-            return 'magic';
-        }
-
-        return 'method';
+        return str_starts_with($nameToken->getContent(), '__')
+            ? 'magic'
+            : 'method'
+        ;
     }
 
     private function findElementEnd(Tokens $tokens, int $index): int

+ 1 - 1
src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php

@@ -72,7 +72,7 @@ final class NoTrailingWhitespaceInCommentFixer extends AbstractFixer
             }
 
             if ($token->isGivenKind(T_COMMENT)) {
-                if ('/*' === substr($token->getContent(), 0, 2)) {
+                if (str_starts_with($token->getContent(), '/*')) {
                     $tokens[$index] = new Token([T_COMMENT, Preg::replace('/(*ANY)[\h]+$/m', '', $token->getContent())]);
                 } elseif (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) {
                     $trimmedContent = ltrim($tokens[$index + 1]->getContent(), " \t");

+ 1 - 1
src/Fixer/Comment/SingleLineCommentStyleFixer.php

@@ -146,7 +146,7 @@ $c = 3;
             if (
                 !$this->asteriskEnabled
                 || str_contains($commentContent, '?>')
-                || '/*' !== substr($content, 0, 2)
+                || !str_starts_with($content, '/*')
                 || 1 === Preg::match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent)
             ) {
                 continue;

+ 4 - 6
src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php

@@ -98,12 +98,10 @@ final class NoAlternativeSyntaxFixer extends AbstractFixer implements Configurab
         $nextIndex = $tokens->getNextMeaningfulToken($structureTokenIndex);
         $nextToken = $tokens[$nextIndex];
 
-        // return if next token is not opening parenthesis
-        if (!$nextToken->equals('(')) {
-            return $structureTokenIndex;
-        }
-
-        return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex);
+        return $nextToken->equals('(')
+            ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex)
+            : $structureTokenIndex // return if next token is not opening parenthesis
+        ;
     }
 
     /**

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

@@ -119,7 +119,7 @@ function foo ($bar) {}
                     : '';
                 $content = Preg::replaceCallback(
                     '/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/',
-                    static function (array $matches) {
+                    static function (array $matches): string {
                         if (\function_exists('mb_strtolower')) {
                             return $matches[1].mb_strtolower($matches[2]).$matches[3];
                         }

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