Browse Source

simplify code, more tests

SpacePossum 3 years ago
parent
commit
0b1320af10

+ 1 - 1
src/AbstractFunctionReferenceFixer.php

@@ -41,7 +41,7 @@ abstract class AbstractFunctionReferenceFixer extends AbstractFixer
     protected function find(string $functionNameToSearch, Tokens $tokens, int $start = 0, ?int $end = null): ?array
     {
         // make interface consistent with findSequence
-        $end = null === $end ? $tokens->count() : $end;
+        $end = $end ?? $tokens->count();
 
         // find raw sequence which we can analyse for context
         $candidateSequence = [[T_STRING, $functionNameToSearch], '('];

+ 1 - 1
src/ConfigurationException/InvalidConfigurationException.php

@@ -30,7 +30,7 @@ class InvalidConfigurationException extends \InvalidArgumentException
     {
         parent::__construct(
             $message,
-            null === $code ? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG : $code,
+            $code ?? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG,
             $previous
         );
     }

+ 1 - 1
src/Console/Command/DescribeCommand.php

@@ -278,7 +278,7 @@ final class DescribeCommand extends Command
                 $configuration = $codeSample->getConfiguration();
 
                 if ($fixer instanceof ConfigurableFixerInterface) {
-                    $fixer->configure(null === $configuration ? [] : $configuration);
+                    $fixer->configure($configuration ?? []);
                 }
 
                 $file = $codeSample instanceof FileSpecificCodeSampleInterface

+ 1 - 3
src/Console/ConfigurationResolver.php

@@ -591,9 +591,7 @@ final class ConfigurationResolver
     private function getFormat(): string
     {
         if (null === $this->format) {
-            $this->format = null === $this->options['format']
-                ? $this->getConfig()->getFormat()
-                : $this->options['format'];
+            $this->format = $this->options['format'] ?? $this->getConfig()->getFormat();
         }
 
         return $this->format;

+ 1 - 5
src/DocBlock/TypeExpression.php

@@ -217,11 +217,7 @@ final class TypeExpression
             'self|static' => 'self',
         ];
 
-        if (isset($parents[$types])) {
-            return $parents[$types];
-        }
-
-        return null;
+        return $parents[$types] ?? null;
     }
 
     private function normalize(string $type): string

+ 1 - 5
src/Documentation/DocumentationGenerator.php

@@ -90,11 +90,7 @@ RST;
         $currentGroup = null;
         foreach ($fixers as $fixer) {
             $namespace = Preg::replace('/^.*\\\\(.+)\\\\.+Fixer$/', '$1', \get_class($fixer));
-            if (isset($overrideGroups[$namespace])) {
-                $group = $overrideGroups[$namespace];
-            } else {
-                $group = Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace);
-            }
+            $group = $overrideGroups[$namespace] ?? Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace);
 
             if ($group !== $currentGroup) {
                 $underline = str_repeat('-', \strlen($group));

+ 1 - 1
src/Fixer/ControlStructure/YodaStyleFixer.php

@@ -459,7 +459,7 @@ return $foo === count($bar);
      * Checks whether the given assignment token has a lower precedence than `T_IS_EQUAL`
      * or `T_IS_IDENTICAL`.
      */
-    private function isOfLowerPrecedenceAssignment(Token $token)
+    private function isOfLowerPrecedenceAssignment(Token $token): bool
     {
         static $tokens;
 

+ 1 - 5
src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php

@@ -408,11 +408,7 @@ class Foo {
             static function (string $type) use ($symbolShortNames) {
                 $type = strtolower($type);
 
-                if (isset($symbolShortNames[$type])) {
-                    return $symbolShortNames[$type];
-                }
-
-                return $type;
+                return $symbolShortNames[$type] ?? $type;
             },
             $types
         );

+ 2 - 4
src/FixerFactory.php

@@ -89,12 +89,10 @@ final class FixerFactory
             $builtInFixers = [];
 
             /** @var SplFileInfo $file */
-            foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer')->depth(1) as $file) {
+            foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer')->name('*Fixer.php')->depth(1) as $file) {
                 $relativeNamespace = $file->getRelativePath();
                 $fixerClass = 'PhpCsFixer\\Fixer\\'.($relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php');
-                if ('Fixer' === substr($fixerClass, -5)) {
-                    $builtInFixers[] = $fixerClass;
-                }
+                $builtInFixers[] = $fixerClass;
             }
         }
 

+ 1 - 1
tests/AbstractFunctionReferenceFixerTest.php

@@ -69,7 +69,7 @@ final class AbstractFunctionReferenceFixerTest extends TestCase
         static::assertFalse($tokens->isChanged());
     }
 
-    public function provideAbstractFunctionReferenceFixerCases()
+    public function provideAbstractFunctionReferenceFixerCases(): array
     {
         return [
             'simple case I' => [

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