Browse Source

DX: more usage of spaceship operator (#7438)

Dariusz Rumiński 1 year ago
parent
commit
60511ca830

+ 1 - 1
src/Console/Report/ListSetsReport/JsonReporter.php

@@ -32,7 +32,7 @@ final class JsonReporter implements ReporterInterface
     {
         $sets = $reportSummary->getSets();
 
-        usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => strcmp($a->getName(), $b->getName()));
+        usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => $a->getName() <=> $b->getName());
 
         $json = ['sets' => []];
 

+ 1 - 1
src/Console/Report/ListSetsReport/TextReporter.php

@@ -32,7 +32,7 @@ final class TextReporter implements ReporterInterface
     {
         $sets = $reportSummary->getSets();
 
-        usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => strcmp($a->getName(), $b->getName()));
+        usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => $a->getName() <=> $b->getName());
 
         $output = '';
 

+ 1 - 1
src/Documentation/FixerDocumentGenerator.php

@@ -267,7 +267,7 @@ final class FixerDocumentGenerator
             'Phpdoc' => 'PHPDoc',
         ];
 
-        usort($fixers, static fn (FixerInterface $a, FixerInterface $b): int => strcmp(\get_class($a), \get_class($b)));
+        usort($fixers, static fn (FixerInterface $a, FixerInterface $b): int => \get_class($a) <=> \get_class($b));
 
         $documentation = <<<'RST'
             =======================

+ 1 - 1
src/Fixer/ClassNotation/OrderedClassElementsFixer.php

@@ -585,7 +585,7 @@ Custom values:
     {
         if (self::SORT_ALPHA === $this->configuration['sort_algorithm']) {
             return $this->configuration['case_sensitive']
-                ? strcmp($a['name'], $b['name'])
+                ? $a['name'] <=> $b['name']
                 : strcasecmp($a['name'], $b['name']);
         }
 

+ 1 - 1
src/Fixer/ClassNotation/OrderedInterfacesFixer.php

@@ -168,7 +168,7 @@ final class OrderedInterfacesFixer extends AbstractFixer implements Configurable
                     ? \strlen($first['normalized']) - \strlen($second['normalized'])
                     : (
                         $this->configuration['case_sensitive']
-                        ? strcmp($first['normalized'], $second['normalized'])
+                        ? $first['normalized'] <=> $second['normalized']
                         : strcasecmp($first['normalized'], $second['normalized'])
                     );
 

+ 1 - 1
src/Fixer/ClassNotation/OrderedTraitsFixer.php

@@ -186,7 +186,7 @@ final class OrderedTraitsFixer extends AbstractFixer implements ConfigurableFixe
         uasort(
             $sortedElements,
             fn (Tokens $useA, Tokens $useB): int => $this->configuration['case_sensitive']
-                ? strcmp($toTraitName($useA), $toTraitName($useB))
+                ? $toTraitName($useA) <=> $toTraitName($useB)
                 : strcasecmp($toTraitName($useA), $toTraitName($useB))
         );
 

+ 1 - 1
src/Fixer/ClassNotation/OrderedTypesFixer.php

@@ -369,7 +369,7 @@ interface Bar
             }
 
             if ('alpha' === $this->configuration['sort_algorithm']) {
-                return $this->configuration['case_sensitive'] ? strcmp($a, $b) : strcasecmp($a, $b);
+                return $this->configuration['case_sensitive'] ? $a <=> $b : strcasecmp($a, $b);
             }
 
             return 0;

+ 2 - 2
src/Fixer/Import/GroupImportFixer.php

@@ -89,9 +89,9 @@ final class GroupImportFixer extends AbstractFixer
             $namespaceA = $this->getNamespaceNameWithSlash($a);
             $namespaceB = $this->getNamespaceNameWithSlash($b);
 
-            $namespaceDifference = \strlen($namespaceA) - \strlen($namespaceB);
+            $namespaceDifference = \strlen($namespaceA) <=> \strlen($namespaceB);
 
-            return 0 !== $namespaceDifference ? $namespaceDifference : strcmp($a->getFullName(), $b->getFullName());
+            return 0 !== $namespaceDifference ? $namespaceDifference : $a->getFullName() <=> $b->getFullName();
         });
 
         return $sameNamespaceAnalysis;

+ 2 - 2
src/Fixer/Import/OrderedImportsFixer.php

@@ -289,7 +289,7 @@ use Bar;
         $secondNamespace = str_replace('\\', ' ', $this->prepareNamespace($second['namespace']));
 
         return true === $this->configuration['case_sensitive']
-            ? strcmp($firstNamespace, $secondNamespace)
+            ? $firstNamespace <=> $secondNamespace
             : strcasecmp($firstNamespace, $secondNamespace);
     }
 
@@ -311,7 +311,7 @@ use Bar;
 
         if ($firstNamespaceLength === $secondNamespaceLength) {
             $sortResult = true === $this->configuration['case_sensitive']
-                ? strcmp($firstNamespace, $secondNamespace)
+                ? $firstNamespace <=> $secondNamespace
                 : strcasecmp($firstNamespace, $secondNamespace);
         } else {
             $sortResult = $firstNamespaceLength > $secondNamespaceLength ? 1 : -1;

+ 1 - 1
src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php

@@ -188,7 +188,7 @@ $className = Baz::class;
                 $classStringArray = explode('\\', $classString);
                 $namespaceToTest = $classStringArray[0];
 
-                if (0 === strcmp($namespaceToTest, substr($import, -\strlen($namespaceToTest)))) {
+                if (0 === ($namespaceToTest <=> substr($import, -\strlen($namespaceToTest)))) {
                     $classImport = $import;
 
                     break;

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