Skip to content

Commit

Permalink
Merge pull request cakephp#17781 from Harfusha/Rector_CountArrayToEmp…
Browse files Browse the repository at this point in the history
…tyArrayComparisonRector

Add changes from rector rule CountArrayToEmptyArrayComparisonRector
  • Loading branch information
ADmad authored Aug 4, 2024
2 parents 08f2330 + 80d3c1b commit 244319b
Show file tree
Hide file tree
Showing 25 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Command/Helper/TableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function _rowSeparator(array $widths): void
*/
protected function _render(array $row, array $widths, array $options = []): void
{
if (count($row) === 0) {
if ($row === []) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/I18nExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function _getPaths(ConsoleIo $io): void
);
$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)
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function outputPaths(ConsoleIo $io): void
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);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/TestSuite/ConsoleIntegrationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function exec(string $command, array $input = []): void
$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;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Expression/WhenThenExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function when(object|array|string|float|int|bool $when, array|string|null
$typeMap = clone $this->_typeMap;
if (
is_array($type) &&
count($type) > 0
$type !== []
) {
$typeMap = $typeMap->setTypes($type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Schema/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function describe(string $name, array $options = []): TableSchemaInterfac
$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));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Error/Debug/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function exportArray(ArrayNode $var, int $indent): string
}

$close = $this->style('punct', ']');
if (count($vars)) {
if ($vars !== []) {
return $out . implode($this->style('punct', ','), $vars) . $end . $close;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ protected function exportObject(ClassNode|ReferenceNode $var, int $indent): stri
$this->export($property->getValue(), $indent);
}
}
if (count($props)) {
if ($props !== []) {
return $out . $break . implode($break, $props) . $end;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Error/Debug/HtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected function exportObject(ClassNode|ReferenceNode $var, int $indent): stri
$this->style('punct', '}') .
'</span>';

if (count($props)) {
if ($props !== []) {
return $out . implode('', $props) . $end;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Error/Debug/TextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function exportArray(ArrayNode $var, int $indent): string
$val = $item->getValue();
$vars[] = $break . $this->export($item->getKey(), $indent) . ' => ' . $this->export($val, $indent);
}
if (count($vars)) {
if ($vars !== []) {
return $out . implode(',', $vars) . $end . ']';
}

Expand Down Expand Up @@ -145,7 +145,7 @@ protected function exportObject(ClassNode|ReferenceNode $var, int $indent): stri
$props[] = "{$name} => " . $this->export($property->getValue(), $indent);
}
}
if (count($props)) {
if ($props !== []) {
return $out . $break . implode($break, $props) . $end;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function validate(array $data, ?string $validator = null): bool
$this->_errors = $this->getValidator($validator ?: static::DEFAULT_VALIDATOR)
->validate($data);

return count($this->_errors) === 0;
return $this->_errors === [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Form/FormProtector.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ protected function matchExistingFields(
*/
protected function debugExpectedFields(array $expectedFields = [], string $missingMessage = ''): ?string
{
if (count($expectedFields) === 0) {
if ($expectedFields === []) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function clientIp(): string
{
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mailer/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ protected function generateMessage(): array
$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);
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Association/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ function () use ($sourceEntity, $targetEntities, $primaryValue, $options) {

$property = $this->getProperty();

if (count($inserts)) {
if ($inserts !== []) {
/** @psalm-suppress RedundantConditionGivenDocblockType */
$inserted = array_combine(
array_keys($inserts),
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Association/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function unlink(EntityInterface $sourceEntity, array $targetEntities, arr
} else {
$options += ['cleanProperty' => true];
}
if (count($targetEntities) === 0) {
if ($targetEntities === []) {
return;
}

Expand Down Expand Up @@ -489,7 +489,7 @@ function ($v) {

$conditions = $foreignKeyReference;

if (count($exclusions) > 0) {
if ($exclusions !== []) {
$conditions = [
'NOT' => [
'OR' => $exclusions,
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ protected function _update(EntityInterface $entity, array $data): EntityInterfac
return $entity;
}

if (count($primaryColumns) === 0) {
if ($primaryColumns === []) {
$entityClass = $entity::class;
$table = $this->getTable();
$message = "Cannot update `$entityClass`. The `$table` has no primary key.";
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function parse(string $url, string $method): ?array

$route['_route'] = $this;
$route['_matchedRoute'] = $this->template;
if (count($this->middleware) > 0) {
if ($this->middleware !== []) {
$route['_middleware'] = $this->middleware;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function add(Route $route, array $options = []): void
$path = $route->staticPath();

$extensions = $route->getExtensions();
if (count($extensions) > 0) {
if ($extensions !== []) {
$this->setExtensions($extensions);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/Constraint/Email/NoMailSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NoMailSent extends MailConstraintBase
*/
public function matches(mixed $other): bool
{
return count($this->getMessages()) === 0;
return $this->getMessages() === [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/IntegrationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ protected function _sendRequest(array|string $url, string $method, array|string
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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/MiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(HttpApplicationInterface $app)
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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public static function check(array $data, string $path): bool
return false;
}

return count($results) > 0;
return $results !== [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Form/FormContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function hasError(string $field): bool
{
$errors = $this->error($field);

return count($errors) > 0;
return $errors !== [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ protected function _isDisabled(array $options): bool
fn ($i) => in_array($i['value'], $options['disabled'], true)
);

return count($disabled) > 0;
return $disabled !== [];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/View/Widget/WidgetLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function _resolveWidget(array|string $config): WidgetInterface
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) {
Expand Down

0 comments on commit 244319b

Please sign in to comment.