Browse Source

Add changes from rector rule CountArrayToEmptyArrayComparisonRector

Adam Halfar 1 year ago
parent
commit
53e0b4e864

+ 1 - 1
src/Command/Helper/TableHelper.php

@@ -106,7 +106,7 @@ class TableHelper extends Helper
      */
     protected function _render(array $row, array $widths, array $options = []): void
     {
-        if (count($row) === 0) {
+        if ($row === []) {
             return;
         }
 

+ 1 - 1
src/Command/I18nExtractCommand.php

@@ -140,7 +140,7 @@ class I18nExtractCommand extends Command
         );
         $defaultPathIndex = 0;
         while (true) {
-            $currentPaths = count($this->_paths) > 0 ? $this->_paths : ['None'];
+            $currentPaths = $this->_paths !== [] ? $this->_paths : ['None'];
             $message = sprintf(
                 "Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
                 implode(', ', $currentPaths)

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

@@ -159,7 +159,7 @@ class HelpCommand extends BaseCommand implements CommandCollectionAwareInterface
         if (defined('CORE_PATH')) {
             $paths['core'] = rtrim(CORE_PATH, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         }
-        if (!count($paths)) {
+        if ($paths === []) {
             return;
         }
         $io->out('<info>Current Paths:</info>', 2);

+ 1 - 1
src/Console/TestSuite/ConsoleIntegrationTestTrait.php

@@ -101,7 +101,7 @@ trait ConsoleIntegrationTestTrait
             $this->_exitCode = $runner->run($args, $io);
         } catch (MissingConsoleInputException $e) {
             $messages = $this->_out->messages();
-            if (count($messages)) {
+            if ($messages !== []) {
                 $e->setQuestion($messages[count($messages) - 1]);
             }
             throw $e;

+ 1 - 1
src/Database/Expression/WhenThenExpression.php

@@ -140,7 +140,7 @@ class WhenThenExpression implements ExpressionInterface
             $typeMap = clone $this->_typeMap;
             if (
                 is_array($type) &&
-                count($type) > 0
+                $type !== []
             ) {
                 $typeMap = $typeMap->setTypes($type);
             }

+ 1 - 1
src/Database/Schema/Collection.php

@@ -114,7 +114,7 @@ class Collection implements CollectionInterface
         $table = $this->_connection->getDriver()->newTableSchema($name);
 
         $this->_reflect('Column', $name, $config, $table);
-        if (count($table->columns()) === 0) {
+        if ($table->columns() === []) {
             throw new DatabaseException(sprintf('Cannot describe %s. It has 0 columns.', $name));
         }
 

+ 2 - 2
src/Error/Debug/ConsoleFormatter.php

@@ -163,7 +163,7 @@ class ConsoleFormatter implements FormatterInterface
         }
 
         $close = $this->style('punct', ']');
-        if (count($vars)) {
+        if ($vars !== []) {
             return $out . implode($this->style('punct', ','), $vars) . $end . $close;
         }
 
@@ -215,7 +215,7 @@ class ConsoleFormatter implements FormatterInterface
                     $this->export($property->getValue(), $indent);
             }
         }
-        if (count($props)) {
+        if ($props !== []) {
             return $out . $break . implode($break, $props) . $end;
         }
 

+ 1 - 1
src/Error/Debug/HtmlFormatter.php

@@ -250,7 +250,7 @@ class HtmlFormatter implements FormatterInterface
             $this->style('punct', '}') .
             '</span>';
 
-        if (count($props)) {
+        if ($props !== []) {
             return $out . implode('', $props) . $end;
         }
 

+ 2 - 2
src/Error/Debug/TextFormatter.php

@@ -108,7 +108,7 @@ TEXT;
             $val = $item->getValue();
             $vars[] = $break . $this->export($item->getKey(), $indent) . ' => ' . $this->export($val, $indent);
         }
-        if (count($vars)) {
+        if ($vars !== []) {
             return $out . implode(',', $vars) . $end . ']';
         }
 
@@ -145,7 +145,7 @@ TEXT;
                 $props[] = "{$name} => " . $this->export($property->getValue(), $indent);
             }
         }
-        if (count($props)) {
+        if ($props !== []) {
             return $out . $break . implode($break, $props) . $end;
         }
 

+ 1 - 1
src/Form/Form.php

@@ -192,7 +192,7 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
         $this->_errors = $this->getValidator($validator ?: static::DEFAULT_VALIDATOR)
             ->validate($data);
 
-        return count($this->_errors) === 0;
+        return $this->_errors === [];
     }
 
     /**

+ 1 - 1
src/Form/FormProtector.php

@@ -560,7 +560,7 @@ class FormProtector
      */
     protected function debugExpectedFields(array $expectedFields = [], string $missingMessage = ''): ?string
     {
-        if (count($expectedFields) === 0) {
+        if ($expectedFields === []) {
             return null;
         }
 

+ 1 - 1
src/Http/ServerRequest.php

@@ -377,7 +377,7 @@ class ServerRequest implements ServerRequestInterface
     {
         if ($this->trustProxy && $this->getEnv('HTTP_X_FORWARDED_FOR')) {
             $addresses = array_map('trim', explode(',', (string)$this->getEnv('HTTP_X_FORWARDED_FOR')));
-            $trusted = (count($this->trustedProxies) > 0);
+            $trusted = ($this->trustedProxies !== []);
             $n = count($addresses);
 
             if ($trusted) {

+ 1 - 1
src/Mailer/Message.php

@@ -1307,7 +1307,7 @@ class Message implements JsonSerializable
         $msg = [];
 
         $contentIds = array_filter((array)Hash::extract($this->attachments, '{s}.contentId'));
-        $hasInlineAttachments = count($contentIds) > 0;
+        $hasInlineAttachments = $contentIds !== [];
         $hasAttachments = !empty($this->attachments);
         $hasMultipleTypes = $this->emailFormat === static::MESSAGE_BOTH;
         $multiPart = ($hasAttachments || $hasMultipleTypes);

+ 1 - 1
src/ORM/Association/BelongsToMany.php

@@ -1237,7 +1237,7 @@ class BelongsToMany extends Association
 
                 $property = $this->getProperty();
 
-                if (count($inserts)) {
+                if ($inserts !== []) {
                     /** @psalm-suppress RedundantConditionGivenDocblockType */
                     $inserted = array_combine(
                         array_keys($inserts),

+ 2 - 2
src/ORM/Association/HasMany.php

@@ -355,7 +355,7 @@ class HasMany extends Association
         } else {
             $options += ['cleanProperty' => true];
         }
-        if (count($targetEntities) === 0) {
+        if ($targetEntities === []) {
             return;
         }
 
@@ -489,7 +489,7 @@ class HasMany extends Association
 
         $conditions = $foreignKeyReference;
 
-        if (count($exclusions) > 0) {
+        if ($exclusions !== []) {
             $conditions = [
                 'NOT' => [
                     'OR' => $exclusions,

+ 1 - 1
src/ORM/Table.php

@@ -2243,7 +2243,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
             return $entity;
         }
 
-        if (count($primaryColumns) === 0) {
+        if ($primaryColumns === []) {
             $entityClass = $entity::class;
             $table = $this->getTable();
             $message = "Cannot update `$entityClass`. The `$table` has no primary key.";

+ 1 - 1
src/Routing/Route/Route.php

@@ -517,7 +517,7 @@ class Route
 
         $route['_route'] = $this;
         $route['_matchedRoute'] = $this->template;
-        if (count($this->middleware) > 0) {
+        if ($this->middleware !== []) {
             $route['_middleware'] = $this->middleware;
         }
 

+ 1 - 1
src/Routing/RouteCollection.php

@@ -115,7 +115,7 @@ class RouteCollection
         $path = $route->staticPath();
 
         $extensions = $route->getExtensions();
-        if (count($extensions) > 0) {
+        if ($extensions !== []) {
             $this->setExtensions($extensions);
         }
 

+ 1 - 1
src/TestSuite/Constraint/Email/NoMailSent.php

@@ -31,7 +31,7 @@ class NoMailSent extends MailConstraintBase
      */
     public function matches(mixed $other): bool
     {
-        return count($this->getMessages()) === 0;
+        return $this->getMessages() === [];
     }
 
     /**

+ 1 - 1
src/TestSuite/IntegrationTestTrait.php

@@ -524,7 +524,7 @@ trait IntegrationTestTrait
     public function resolveUrl(array|string $url): string
     {
         // If we need to resolve a Route URL but there are no routes, load routes.
-        if (is_array($url) && count(Router::getRouteCollection()->routes()) === 0) {
+        if (is_array($url) && Router::getRouteCollection()->routes() === []) {
             return $this->resolveRoute($url);
         }
 

+ 1 - 1
src/TestSuite/MiddlewareDispatcher.php

@@ -60,7 +60,7 @@ class MiddlewareDispatcher
     public function resolveUrl(array|string $url): string
     {
         // If we need to resolve a Route URL but there are no routes, load routes.
-        if (is_array($url) && count(Router::getRouteCollection()->routes()) === 0) {
+        if (is_array($url) && Router::getRouteCollection()->routes() === []) {
             return $this->resolveRoute($url);
         }
 

+ 1 - 1
src/Utility/Hash.php

@@ -647,7 +647,7 @@ class Hash
             return false;
         }
 
-        return count($results) > 0;
+        return $results !== [];
     }
 
     /**

+ 1 - 1
src/View/Form/FormContext.php

@@ -218,7 +218,7 @@ class FormContext implements ContextInterface
     {
         $errors = $this->error($field);
 
-        return count($errors) > 0;
+        return $errors !== [];
     }
 
     /**

+ 1 - 1
src/View/Helper/FormHelper.php

@@ -2421,7 +2421,7 @@ class FormHelper extends Helper
                     fn ($i) => in_array($i['value'], $options['disabled'], true)
                 );
 
-                return count($disabled) > 0;
+                return $disabled !== [];
             }
         }
 

+ 1 - 1
src/View/Widget/WidgetLocator.php

@@ -198,7 +198,7 @@ class WidgetLocator
         if ($className === null) {
             throw new InvalidArgumentException(sprintf('Unable to locate widget class `%s`.', $class));
         }
-        if (count($config)) {
+        if ($config !== []) {
             $reflection = new ReflectionClass($className);
             $arguments = [$this->_templates];
             foreach ($config as $requirement) {