Browse Source

SCA/utilize PHP8.1

SpacePossum 3 years ago
parent
commit
e483ac0c9f

+ 1 - 1
src/Cache/Cache.php

@@ -114,7 +114,7 @@ final class Cache implements CacheInterface
 
         $missingKeys = array_diff_key(array_flip($requiredKeys), $data);
 
-        if (\count($missingKeys)) {
+        if (\count($missingKeys) > 0) {
             throw new \InvalidArgumentException(sprintf(
                 'JSON data is missing keys "%s"',
                 implode('", "', $missingKeys)

+ 1 - 1
src/Cache/FileCacheManager.php

@@ -122,7 +122,7 @@ final class FileCacheManager implements CacheManagerInterface
     {
         $cache = $this->handler->read();
 
-        if (!$cache || !$this->signature->equals($cache->getSignature())) {
+        if (null === $cache || !$this->signature->equals($cache->getSignature())) {
             $cache = new Cache($this->signature);
         }
 

+ 3 - 2
src/Console/Application.php

@@ -86,7 +86,7 @@ final class Application extends BaseApplication
             $warningsDetector->detectOldMajor();
             $warnings = $warningsDetector->getWarnings();
 
-            if ($warnings) {
+            if (\count($warnings) > 0) {
                 foreach ($warnings as $warning) {
                     $stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
                 }
@@ -101,7 +101,8 @@ final class Application extends BaseApplication
             && $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE
         ) {
             $triggeredDeprecations = Utils::getTriggeredDeprecations();
-            if ($triggeredDeprecations) {
+
+            if (\count($triggeredDeprecations) > 0) {
                 $stdErr->writeln('');
                 $stdErr->writeln($stdErr->isDecorated() ? '<bg=yellow;fg=black;>Detected deprecations in use:</>' : 'Detected deprecations in use:');
                 foreach ($triggeredDeprecations as $deprecation) {

+ 10 - 8
src/Console/Command/DescribeCommand.php

@@ -107,7 +107,7 @@ final class DescribeCommand extends Command
         $name = $input->getArgument('name');
 
         try {
-            if ('@' === $name[0]) {
+            if (str_starts_with($name, '@')) {
                 $this->describeSet($output, $name);
 
                 return 0;
@@ -147,7 +147,7 @@ final class DescribeCommand extends Command
 
         $definition = $fixer->getDefinition();
 
-        $description = $definition->getSummary();
+        $summary = $definition->getSummary();
 
         if ($fixer instanceof DeprecatedFixerInterface) {
             $successors = $fixer->getSuccessorsNames();
@@ -155,7 +155,7 @@ final class DescribeCommand extends Command
                 ? 'will be removed on next major version'
                 : sprintf('use %s instead', Utils::naturalLanguageJoinWithBackticks($successors));
             $message = Preg::replace('/(`.+?`)/', '<info>$1</info>', $message);
-            $description .= sprintf(' <error>DEPRECATED</error>: %s.', $message);
+            $summary .= sprintf(' <error>DEPRECATED</error>: %s.', $message);
         }
 
         $output->writeln(sprintf('<info>Description of</info> %s <info>rule</info>.', $name));
@@ -164,10 +164,12 @@ final class DescribeCommand extends Command
             $output->writeln(sprintf('Fixer class: <comment>%s</comment>.', \get_class($fixer)));
         }
 
-        $output->writeln($description);
+        $output->writeln($summary);
 
-        if ($definition->getDescription()) {
-            $output->writeln($definition->getDescription());
+        $description = $definition->getDescription();
+
+        if (null !== $description) {
+            $output->writeln($description);
         }
 
         $output->writeln('');
@@ -250,7 +252,7 @@ final class DescribeCommand extends Command
             return true;
         });
 
-        if (!\count($codeSamples)) {
+        if (0 === \count($codeSamples)) {
             $output->writeln([
                 'Fixing examples can not be demonstrated on the current PHP version.',
                 '',
@@ -322,7 +324,7 @@ final class DescribeCommand extends Command
         $help = '';
 
         foreach ($ruleSetDefinitions[$name]->getRules() as $rule => $config) {
-            if ('@' === $rule[0]) {
+            if (str_starts_with($rule, '@')) {
                 $set = $ruleSetDefinitions[$rule];
                 $help .= sprintf(
                     " * <info>%s</info>%s\n   | %s\n\n",

+ 7 - 5
src/Console/ConfigurationResolver.php

@@ -342,7 +342,7 @@ final class ConfigurationResolver
                     )
                 );
 
-                if (\count($riskyFixers)) {
+                if (\count($riskyFixers) > 0) {
                     throw new InvalidConfigurationException(sprintf('The rules contain risky fixers ("%s"), but they are not allowed to run. Perhaps you forget to use --allow-risky=yes option?', implode('", "', $riskyFixers)));
                 }
             }
@@ -638,8 +638,9 @@ final class ConfigurationResolver
             throw new InvalidConfigurationException('Empty rules value is not allowed.');
         }
 
-        if ('{' === $rules[0]) {
+        if (str_starts_with($rules, '{')) {
             $rules = json_decode($rules, true);
+
             if (JSON_ERROR_NONE !== json_last_error()) {
                 throw new InvalidConfigurationException(sprintf('Invalid JSON rules input: "%s".', json_last_error_msg()));
             }
@@ -651,11 +652,12 @@ final class ConfigurationResolver
 
         foreach (explode(',', $this->options['rules']) as $rule) {
             $rule = trim($rule);
+
             if ('' === $rule) {
                 throw new InvalidConfigurationException('Empty rule name is not allowed.');
             }
 
-            if ('-' === $rule[0]) {
+            if (str_starts_with($rule, '-')) {
                 $rules[substr($rule, 1)] = false;
             } else {
                 $rules[$rule] = true;
@@ -702,7 +704,7 @@ final class ConfigurationResolver
             $availableFixers
         );
 
-        if (\count($unknownFixers)) {
+        if (\count($unknownFixers) > 0) {
             $renamedRules = [
                 'blank_line_before_return' => [
                     'new_name' => 'blank_line_before_statement',
@@ -835,7 +837,7 @@ final class ConfigurationResolver
             $this->getPath()
         ));
 
-        if (!\count($paths)) {
+        if (0 === \count($paths)) {
             if ($isIntersectionPathMode) {
                 return new \ArrayIterator([]);
             }

+ 1 - 1
src/Console/WarningsDetector.php

@@ -66,7 +66,7 @@ final class WarningsDetector
      */
     public function getWarnings(): array
     {
-        if (!\count($this->warnings)) {
+        if (0 === \count($this->warnings)) {
             return [];
         }
 

+ 1 - 1
src/DocBlock/DocBlock.php

@@ -171,7 +171,7 @@ final class DocBlock
         }
 
         $lineContent = '';
-        if (\count($usefulLines)) {
+        if (\count($usefulLines) > 0) {
             $lineContent = $this->getSingleLineDocBlockEntry(array_shift($usefulLines));
         }
 

+ 1 - 1
src/Documentation/DocumentationGenerator.php

@@ -365,7 +365,7 @@ RST;
             $doc .= "Rules\n-----\n";
 
             foreach ($rules as $rule => $config) {
-                if ('@' === $rule[0]) {
+                if (str_starts_with($rule, '@')) {
                     $ruleSetPath = $this->getRuleSetsDocumentationFilePath($rule);
                     $ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/'));
 

+ 1 - 1
src/Fixer/Basic/NonPrintableCharacterFixer.php

@@ -143,7 +143,7 @@ final class NonPrintableCharacterFixer extends AbstractFixer implements Configur
                         $tokens[$index - 1] = new Token([T_START_HEREDOC, str_replace('\'', '', $previousTokenContent)]);
                         $stringTypeChanged = true;
                     }
-                } elseif ("'" === $content[0]) {
+                } elseif (str_starts_with($content, "'")) {
                     $stringTypeChanged = true;
                     $swapQuotes = true;
                 }

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

@@ -47,7 +47,7 @@ final class FinalInternalClassFixer extends AbstractFixer implements Configurabl
             $this->configuration['annotation_exclude']
         );
 
-        if (\count($intersect)) {
+        if (\count($intersect) > 0) {
             throw new InvalidFixerConfigurationException($this->getName(), sprintf('Annotation cannot be used in both the include and exclude list, got duplicates: "%s".', implode('", "', array_keys($intersect))));
         }
     }

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