diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 1493398334c1..7acea4e7e82e 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -18,7 +18,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 13, + 'count' => 10, 'path' => __DIR__ . '/system/Autoloader/FileLocator.php', ]; $ignoreErrors[] = [ @@ -33,7 +33,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 16, + 'count' => 10, 'path' => __DIR__ . '/system/BaseModel.php', ]; $ignoreErrors[] = [ @@ -63,7 +63,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 5, + 'count' => 2, 'path' => __DIR__ . '/system/CLI/BaseCommand.php', ]; $ignoreErrors[] = [ @@ -83,7 +83,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 1, 'path' => __DIR__ . '/system/CLI/CLI.php', ]; $ignoreErrors[] = [ @@ -856,11 +856,6 @@ 'count' => 4, 'path' => __DIR__ . '/system/Config/Services.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Controller.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#', 'count' => 1, @@ -1033,7 +1028,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 10, + 'count' => 2, 'path' => __DIR__ . '/system/Database/BaseResult.php', ]; $ignoreErrors[] = [ @@ -1148,7 +1143,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 8, + 'count' => 6, 'path' => __DIR__ . '/system/Database/MigrationRunner.php', ]; $ignoreErrors[] = [ @@ -1206,11 +1201,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/ModelFactory.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/MySQLi/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 12, @@ -1543,7 +1533,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 15, + 'count' => 10, 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', ]; $ignoreErrors[] = [ @@ -1593,7 +1583,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 5, 'path' => __DIR__ . '/system/Database/SQLSRV/Forge.php', ]; $ignoreErrors[] = [ @@ -1713,7 +1703,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, + 'count' => 2, 'path' => __DIR__ . '/system/Database/SQLite3/Table.php', ]; $ignoreErrors[] = [ @@ -1761,11 +1751,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/Debug/Exceptions.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Iterator.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 5, @@ -1773,24 +1758,14 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 5, + 'count' => 2, 'path' => __DIR__ . '/system/Debug/Toolbar.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Toolbar/Collectors/Database.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Debug/Toolbar/Collectors/Database.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Toolbar/Collectors/History.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 2, @@ -1888,7 +1863,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 4, + 'count' => 3, 'path' => __DIR__ . '/system/Entity/Entity.php', ]; $ignoreErrors[] = [ @@ -1958,7 +1933,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 2, + 'count' => 1, 'path' => __DIR__ . '/system/HTTP/CLIRequest.php', ]; $ignoreErrors[] = [ @@ -1978,7 +1953,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 9, + 'count' => 7, 'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php', ]; $ignoreErrors[] = [ @@ -2031,11 +2006,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Files/FileCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#', 'count' => 2, @@ -2133,7 +2103,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, + 'count' => 2, 'path' => __DIR__ . '/system/HTTP/Negotiate.php', ]; $ignoreErrors[] = [ @@ -2188,7 +2158,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 5, 'path' => __DIR__ . '/system/HTTP/Response.php', ]; $ignoreErrors[] = [ @@ -2266,11 +2236,6 @@ 'count' => 4, 'path' => __DIR__ . '/system/HTTP/UserAgent.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, - 'path' => __DIR__ . '/system/Helpers/array_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, @@ -2358,7 +2323,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 4, + 'count' => 1, 'path' => __DIR__ . '/system/Helpers/form_helper.php', ]; $ignoreErrors[] = [ @@ -2378,7 +2343,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 5, 'path' => __DIR__ . '/system/Helpers/html_helper.php', ]; $ignoreErrors[] = [ @@ -2398,7 +2363,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, + 'count' => 1, 'path' => __DIR__ . '/system/Helpers/text_helper.php', ]; $ignoreErrors[] = [ @@ -2408,7 +2373,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 2, + 'count' => 1, 'path' => __DIR__ . '/system/Helpers/url_helper.php', ]; $ignoreErrors[] = [ @@ -2551,11 +2516,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Log/Handlers/FileHandler.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Log/Logger.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$level \\(string\\) of method CodeIgniter\\\\Log\\\\Logger\\:\\:log\\(\\) should be contravariant with parameter \\$level \\(mixed\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#', 'count' => 1, @@ -2563,7 +2523,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 18, + 'count' => 16, 'path' => __DIR__ . '/system/Model.php', ]; $ignoreErrors[] = [ @@ -2648,7 +2608,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 3, 'path' => __DIR__ . '/system/Router/AutoRouter.php', ]; $ignoreErrors[] = [ @@ -2838,7 +2798,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 5, + 'count' => 4, 'path' => __DIR__ . '/system/Router/Router.php', ]; $ignoreErrors[] = [ @@ -2963,7 +2923,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, + 'count' => 2, 'path' => __DIR__ . '/system/Session/Handlers/MemcachedHandler.php', ]; $ignoreErrors[] = [ @@ -2988,7 +2948,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 13, + 'count' => 12, 'path' => __DIR__ . '/system/Session/Session.php', ]; $ignoreErrors[] = [ @@ -3273,7 +3233,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 7, + 'count' => 6, 'path' => __DIR__ . '/system/Test/DOMParser.php', ]; $ignoreErrors[] = [ @@ -3851,11 +3811,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Validation/CreditCardRules.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Validation/DotArrayFilter.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in a negated boolean, array\\|null given\\.$#', 'count' => 6, @@ -3868,7 +3823,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 11, + 'count' => 8, 'path' => __DIR__ . '/system/Validation/Rules.php', ]; $ignoreErrors[] = [ @@ -3908,7 +3863,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 9, + 'count' => 6, 'path' => __DIR__ . '/system/View/Parser.php', ]; $ignoreErrors[] = [ @@ -3918,12 +3873,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/View/Plugins.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 9, + 'count' => 7, 'path' => __DIR__ . '/system/View/Table.php', ]; $ignoreErrors[] = [ diff --git a/rector.php b/rector.php index cfc84104456e..65f5b8fcbec9 100644 --- a/rector.php +++ b/rector.php @@ -11,6 +11,7 @@ use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; +use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector; use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; @@ -137,6 +138,7 @@ $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); + $rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class); $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); $rectorConfig->rule(CompleteDynamicPropertiesRector::class); diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 92381a7ee25b..e9ce492c54d6 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -196,7 +196,7 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp = } } - if (! $prioritizeApp && ! empty($appPaths)) { + if (! $prioritizeApp && $appPaths !== []) { $foundPaths = [...$foundPaths, ...$appPaths]; } @@ -322,7 +322,7 @@ public function listFiles(string $path): array $tempFiles = get_filenames($fullPath, true, false, false); - if (! empty($tempFiles)) { + if ($tempFiles !== []) { $files = array_merge($files, $tempFiles); } } @@ -356,7 +356,7 @@ public function listNamespaceFiles(string $prefix, string $path): array $tempFiles = get_filenames($fullPath, true, false, false); - if (! empty($tempFiles)) { + if ($tempFiles !== []) { $files = array_merge($files, $tempFiles); } } diff --git a/system/BaseModel.php b/system/BaseModel.php index 0d3df3d465a1..fcda6b134498 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -782,7 +782,7 @@ public function insert($row = null, bool $returnID = true) // doProtectFields() can further remove elements from // $row, so we need to check for empty dataset again - if (! $this->allowEmptyInserts && empty($row)) { + if (! $this->allowEmptyInserts && $row === []) { throw DataException::forEmptyDataset('insert'); } @@ -964,7 +964,7 @@ public function update($id = null, $row = null): bool // doProtectFields() can further remove elements from // $row, so we need to check for empty dataset again - if (empty($row)) { + if ($row === []) { throw DataException::forEmptyDataset('update'); } @@ -1288,7 +1288,7 @@ protected function doProtectFields(array $row): array return $row; } - if (empty($this->allowedFields)) { + if ($this->allowedFields === []) { throw DataException::forInvalidAllowedFields(static::class); } @@ -1510,7 +1510,7 @@ public function validate($row): bool { $rules = $this->getValidationRules(); - if ($this->skipValidation || empty($rules) || empty($row)) { + if ($this->skipValidation || $rules === [] || empty($row)) { return true; } @@ -1523,7 +1523,7 @@ public function validate($row): bool // If no data existed that needs validation // our job is done here. - if (empty($rules)) { + if ($rules === []) { return true; } @@ -1879,7 +1879,7 @@ protected function fillPlaceholders(array $rules, array $data): array $replacements['{' . $key . '}'] = $value; } - if (! empty($replacements)) { + if ($replacements !== []) { foreach ($rules as &$rule) { if (is_array($rule)) { foreach ($rule as &$row) { diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index d837f50dbeef..8101283b908a 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -143,7 +143,7 @@ public function showHelp() } else { $usage = $this->name; - if (! empty($this->arguments)) { + if ($this->arguments !== []) { $usage .= ' [arguments]'; } } @@ -156,7 +156,7 @@ public function showHelp() CLI::write($this->setPad($this->description, 0, 0, 2)); } - if (! empty($this->arguments)) { + if ($this->arguments !== []) { CLI::newLine(); CLI::write(lang('CLI.helpArguments'), 'yellow'); $length = max(array_map('strlen', array_keys($this->arguments))); @@ -166,7 +166,7 @@ public function showHelp() } } - if (! empty($this->options)) { + if ($this->options !== []) { CLI::newLine(); CLI::write(lang('CLI.helpOptions'), 'yellow'); $length = max(array_map('strlen', array_keys($this->options))); diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 50a846a25e05..64b576735486 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -252,7 +252,7 @@ public static function prompt(string $field, $options = null, $validation = null unset($opts[0]); - if (empty($opts)) { + if ($opts === []) { $extraOutput = $extraOutputDefault; } else { $extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $opts) . ']'; @@ -324,7 +324,7 @@ public static function promptByMultipleKeys(string $text, array $options): array $opts = $options; unset($opts[0]); - if (empty($opts)) { + if ($opts === []) { $extraOutput = $extraOutputDefault; } else { $optsKey = []; @@ -1000,7 +1000,7 @@ public static function getOptions(): array */ public static function getOptionString(bool $useLongOpts = false, bool $trim = false): string { - if (empty(static::$options)) { + if (static::$options === []) { return ''; } @@ -1041,7 +1041,7 @@ public static function table(array $tbody, array $thead = []) $tableRows = []; // We need only indexes and not keys - if (! empty($thead)) { + if ($thead !== []) { $tableRows[] = array_values($thead); } @@ -1115,7 +1115,7 @@ public static function table(array $tbody, array $thead = []) $table .= '| ' . implode(' | ', $tableRows[$row]) . ' |' . PHP_EOL; // Set the thead and table borders-bottom - if (($row === 0 && ! empty($thead)) || ($row + 1 === $totalRows)) { + if (($row === 0 && $thead !== []) || ($row + 1 === $totalRows)) { $table .= $cols . PHP_EOL; } } diff --git a/system/Controller.php b/system/Controller.php index c040e1d20a4f..a28a7a59f460 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -132,7 +132,7 @@ protected function cachePage(int $time) */ protected function loadHelpers() { - if (empty($this->helpers)) { + if ($this->helpers === []) { return; } diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 6f6399cfb2fd..b807b0bb7ff0 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -174,7 +174,7 @@ public function getCustomResultObject(string $className) */ public function getResultArray(): array { - if (! empty($this->resultArray)) { + if ($this->resultArray !== []) { return $this->resultArray; } @@ -214,7 +214,7 @@ public function getResultArray(): array */ public function getResultObject(): array { - if (! empty($this->resultObject)) { + if ($this->resultObject !== []) { return $this->resultObject; } @@ -323,7 +323,7 @@ public function getCustomRowObject(int $n, string $className) public function getRowArray(int $n = 0) { $result = $this->getResultArray(); - if (empty($result)) { + if ($result === []) { return null; } @@ -344,7 +344,7 @@ public function getRowArray(int $n = 0) public function getRowObject(int $n = 0) { $result = $this->getResultObject(); - if (empty($result)) { + if ($result === []) { return null; } @@ -392,7 +392,7 @@ public function getFirstRow(string $type = 'object') { $result = $this->getResult($type); - return (empty($result)) ? null : $result[0]; + return ($result === []) ? null : $result[0]; } /** @@ -404,7 +404,7 @@ public function getLastRow(string $type = 'object') { $result = $this->getResult($type); - return (empty($result)) ? null : $result[count($result) - 1]; + return ($result === []) ? null : $result[count($result) - 1]; } /** @@ -415,7 +415,7 @@ public function getLastRow(string $type = 'object') public function getNextRow(string $type = 'object') { $result = $this->getResult($type); - if (empty($result)) { + if ($result === []) { return null; } @@ -430,7 +430,7 @@ public function getNextRow(string $type = 'object') public function getPreviousRow(string $type = 'object') { $result = $this->getResult($type); - if (empty($result)) { + if ($result === []) { return null; } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 3a17646ca121..af8f191c276c 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -167,7 +167,7 @@ public function latest(?string $group = null) $migrations = $this->findMigrations(); - if (empty($migrations)) { + if ($migrations === []) { return true; } @@ -235,7 +235,7 @@ public function regress(int $targetBatch = 0, ?string $group = null) $targetBatch = $batches[count($batches) - 1 + $targetBatch] ?? 0; } - if (empty($batches) && $targetBatch === 0) { + if ($batches === [] && $targetBatch === 0) { return true; } diff --git a/system/Database/MySQLi/Builder.php b/system/Database/MySQLi/Builder.php index 2b95aedcea00..096bbedd888c 100644 --- a/system/Database/MySQLi/Builder.php +++ b/system/Database/MySQLi/Builder.php @@ -49,7 +49,7 @@ class Builder extends BaseBuilder */ protected function _fromTables(): string { - if (! empty($this->QBJoin) && count($this->QBFrom) > 1) { + if ($this->QBJoin !== [] && count($this->QBFrom) > 1) { return '(' . implode(', ', $this->QBFrom) . ')'; } diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php index 5e3e4a73bb11..b4e77f1d2cf8 100755 --- a/system/Database/SQLSRV/Builder.php +++ b/system/Database/SQLSRV/Builder.php @@ -332,7 +332,7 @@ public function replace(?array $set = null) $this->set($set); } - if (empty($this->QBSet)) { + if ($this->QBSet === []) { if ($this->db->DBDebug) { throw new DatabaseException('You must use the "set" method to update an entry.'); } @@ -514,7 +514,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true) $this->where($where); } - if (empty($this->QBWhere)) { + if ($this->QBWhere === []) { if ($this->db->DBDebug) { throw new DatabaseException('Deletes are not allowed unless they contain a "where" or "like" clause.'); } @@ -551,7 +551,7 @@ protected function compileSelect($selectOverride = false): string $sql = (! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT '; // SQL Server can't work with select * if group by is specified - if (empty($this->QBSelect) && ! empty($this->QBGroupBy) && is_array($this->QBGroupBy)) { + if (empty($this->QBSelect) && $this->QBGroupBy !== [] && is_array($this->QBGroupBy)) { foreach ($this->QBGroupBy as $field) { $this->QBSelect[] = is_array($field) ? $field['field'] : $field; } @@ -573,7 +573,7 @@ protected function compileSelect($selectOverride = false): string } // Write the "FROM" portion of the query - if (! empty($this->QBFrom)) { + if ($this->QBFrom !== []) { $sql .= "\nFROM " . $this->_fromTables(); } @@ -660,7 +660,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri }); // if no primary found then look for unique - since indexes have no order - if (empty($uniqueIndexes)) { + if ($uniqueIndexes === []) { $uniqueIndexes = array_filter($tableIndexes, static function ($index) use ($fieldNames) { $hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields); diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index e44624761850..ff1ce2e59bb9 100755 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -145,7 +145,7 @@ protected function _alterTable(string $alterType, string $table, $field) $fld = array_intersect($field, $index->fields); // Drop index if field is part of an index - if (! empty($fld)) { + if ($fld !== []) { $this->_dropIndex($table, $index); } } diff --git a/system/Database/SQLite3/Table.php b/system/Database/SQLite3/Table.php index 879437da6f6a..b733e980b30e 100644 --- a/system/Database/SQLite3/Table.php +++ b/system/Database/SQLite3/Table.php @@ -113,7 +113,7 @@ public function fromTable(string $table) // if primary key index exists twice then remove psuedo index name 'primary'. $primaryIndexes = array_filter($this->keys, static fn ($index) => $index['type'] === 'primary'); - if (! empty($primaryIndexes) && count($primaryIndexes) > 1 && array_key_exists('primary', $this->keys)) { + if ($primaryIndexes !== [] && count($primaryIndexes) > 1 && array_key_exists('primary', $this->keys)) { unset($this->keys['primary']); } diff --git a/system/Debug/Iterator.php b/system/Debug/Iterator.php index 2163bb0b2587..4bfb3a5bc88c 100644 --- a/system/Debug/Iterator.php +++ b/system/Debug/Iterator.php @@ -93,7 +93,7 @@ public function run(int $iterations = 1000, bool $output = true) */ public function getReport(): string { - if (empty($this->results)) { + if ($this->results === []) { return 'No results to display.'; } diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 4a7a20632fd7..b99d839265b7 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -121,7 +121,7 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques $data['vars']['varData'][esc($heading)] = $varData; } - if (! empty($_SESSION)) { + if (isset($_SESSION)) { foreach ($_SESSION as $key => $value) { // Replace the binary data with string to avoid json_encode failure. if (is_string($value) && preg_match('~[^\x20-\x7E\t\r\n]~', $value)) { @@ -292,7 +292,7 @@ protected function structureTimelineData(array $elements): array $element = array_shift($elements); // If we have children behind us, collect and attach them to us - while (! empty($elements) && $elements[array_key_first($elements)]['end'] <= $element['end']) { + while ($elements !== [] && $elements[array_key_first($elements)]['end'] <= $element['end']) { $element['children'][] = array_shift($elements); } @@ -302,7 +302,7 @@ protected function structureTimelineData(array $elements): array } // If we have no younger siblings, we can return - if (empty($elements)) { + if ($elements === []) { return [$element]; } diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index b527f2ed3c95..5b5614ad3b9c 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -235,7 +235,7 @@ public function getTitleDetails(): string */ public function isEmpty(): bool { - return empty(static::$queries); + return static::$queries === []; } /** diff --git a/system/Debug/Toolbar/Collectors/History.php b/system/Debug/Toolbar/Collectors/History.php index a639e35a4ebd..fcf06e16f54a 100644 --- a/system/Debug/Toolbar/Collectors/History.php +++ b/system/Debug/Toolbar/Collectors/History.php @@ -128,7 +128,7 @@ public function getBadgeValue(): int */ public function isEmpty(): bool { - return empty($this->files); + return $this->files === []; } /** diff --git a/system/Entity/Entity.php b/system/Entity/Entity.php index 90d3ab46a297..0e751b684843 100644 --- a/system/Entity/Entity.php +++ b/system/Entity/Entity.php @@ -319,7 +319,7 @@ public function setAttributes(array $data) */ protected function mapProperty(string $key) { - if (empty($this->datamap)) { + if ($this->datamap === []) { return $key; } diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 878e8a1d66c6..1d15619c8016 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -147,7 +147,7 @@ public function getOption(string $key) */ public function getOptionString(bool $useLongOpts = false): string { - if (empty($this->options)) { + if ($this->options === []) { return ''; } diff --git a/system/HTTP/ContentSecurityPolicy.php b/system/HTTP/ContentSecurityPolicy.php index 37b0ce650ff7..660d26b6ab88 100644 --- a/system/HTTP/ContentSecurityPolicy.php +++ b/system/HTTP/ContentSecurityPolicy.php @@ -806,11 +806,11 @@ protected function addToHeader(string $name, $values = null) } } - if (! empty($sources)) { + if ($sources !== []) { $this->tempHeaders[$name] = implode(' ', $sources); } - if (! empty($reportSources)) { + if ($reportSources !== []) { $this->reportOnlyHeaders[$name] = implode(' ', $reportSources); } } diff --git a/system/HTTP/Files/FileCollection.php b/system/HTTP/Files/FileCollection.php index 8cb1f913e8dc..124381ec33bb 100644 --- a/system/HTTP/Files/FileCollection.php +++ b/system/HTTP/Files/FileCollection.php @@ -148,7 +148,7 @@ protected function populateFiles() $this->files = []; - if (empty($_FILES)) { + if ($_FILES === []) { return; } diff --git a/system/HTTP/Negotiate.php b/system/HTTP/Negotiate.php index b1d5fdfa93a3..a9297669146a 100644 --- a/system/HTTP/Negotiate.php +++ b/system/HTTP/Negotiate.php @@ -154,7 +154,7 @@ protected function getBestMatch( bool $strictMatch = false, bool $matchLocales = false ): string { - if (empty($supported)) { + if ($supported === []) { throw HTTPException::forEmptySupportedNegotiations(); } diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index 7c0741317bc0..90637fdbd7cf 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -377,7 +377,7 @@ public function noCache() */ public function setCache(array $options = []) { - if (empty($options)) { + if ($options === []) { return $this; } diff --git a/system/Helpers/array_helper.php b/system/Helpers/array_helper.php index 65645c3cc316..b8bd1a4d956f 100644 --- a/system/Helpers/array_helper.php +++ b/system/Helpers/array_helper.php @@ -85,7 +85,7 @@ function _array_search_dot(array $indexes, array $array) // If this is the last index, make sure to return it now, // and not try to recurse through things. - if (empty($indexes)) { + if ($indexes === []) { return $array[$currentIndex]; } @@ -152,7 +152,7 @@ function array_deep_search($key, array $array) function array_sort_by_multiple_keys(array &$array, array $sortColumns): bool { // Check if there really are columns to sort after - if (empty($sortColumns) || empty($array)) { + if ($sortColumns === [] || $array === []) { return false; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 7edb05cf1de3..d3abd7e247b0 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -288,7 +288,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''): } // If no selected state was submitted we will attempt to set it automatically - if (empty($selected)) { + if ($selected === []) { if (is_array($data)) { if (isset($data['name'], $_POST[$data['name']])) { $selected = [$_POST[$data['name']]]; @@ -312,7 +312,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''): $key = (string) $key; if (is_array($val)) { - if (empty($val)) { + if ($val === []) { continue; } @@ -784,7 +784,7 @@ function parse_form_attributes($attributes, array $default): string unset($attributes[$key]); } } - if (! empty($attributes)) { + if ($attributes !== []) { $default = array_merge($default, $attributes); } } diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php index c7a36e270860..88fb339832d1 100755 --- a/system/Helpers/html_helper.php +++ b/system/Helpers/html_helper.php @@ -469,7 +469,7 @@ function object(string $data, string $type = 'unknown', string $attributes = '', $object = ''; - if (! empty($params)) { + if ($params !== []) { $object .= "\n"; } diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 56cf856fbda7..9c8f7be07ec2 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -98,7 +98,7 @@ function ascii_to_entities(string $str): string $out .= $str[$i]; } else { - if (empty($temp)) { + if ($temp === []) { $count = ($ordinal < 224) ? 2 : 3; } @@ -172,7 +172,7 @@ function entities_to_ascii(string $str, bool $all = true): string */ function word_censor(string $str, array $censored, string $replacement = ''): string { - if (empty($censored)) { + if ($censored === []) { return $str; } diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 27e3ce1d079f..8099558aa343 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -290,7 +290,7 @@ function safe_mailto(string $email, string $title = '', $attributes = ''): strin if ($ordinal < 128) { $x[] = '|' . $ordinal; } else { - if (empty($temp)) { + if ($temp === []) { $count = ($ordinal < 224) ? 2 : 3; } diff --git a/system/Log/Logger.php b/system/Log/Logger.php index 0964edc4f3bf..e5f482cb63d2 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -137,7 +137,7 @@ public function __construct($config, bool $debug = CI_DEBUG) $this->dateFormat = $config->dateFormat ?? $this->dateFormat; - if (! is_array($config->handlers) || empty($config->handlers)) { + if (! is_array($config->handlers) || $config->handlers === []) { throw LogException::forNoHandlers('LoggerConfig'); } diff --git a/system/Model.php b/system/Model.php index 4c55aac937bf..a9fd4b312c4a 100644 --- a/system/Model.php +++ b/system/Model.php @@ -297,7 +297,7 @@ protected function doInsert(array $row) $builder->set($key, $val, $escape[$key] ?? null); } - if ($this->allowEmptyInserts && empty($row)) { + if ($this->allowEmptyInserts && $row === []) { $table = $this->db->protectIdentifiers($this->table, true, null, false); if ($this->db->getPlatform() === 'MySQLi') { $sql = 'INSERT INTO ' . $table . ' VALUES ()'; @@ -760,7 +760,7 @@ protected function doProtectFieldsForInsert(array $row): array return $row; } - if (empty($this->allowedFields)) { + if ($this->allowedFields === []) { throw DataException::forInvalidAllowedFields(static::class); } diff --git a/system/Router/AutoRouter.php b/system/Router/AutoRouter.php index f7cd02a3d329..16ec68c87507 100644 --- a/system/Router/AutoRouter.php +++ b/system/Router/AutoRouter.php @@ -90,7 +90,7 @@ public function getRoute(string $uri, string $httpVerb): array // If we don't have any segments left - use the default controller; // If not empty, then the first segment should be the controller - if (! empty($segments)) { + if ($segments !== []) { $this->controller = ucfirst(array_shift($segments)); } @@ -103,7 +103,7 @@ public function getRoute(string $uri, string $httpVerb): array // Use the method name if it exists. // If it doesn't, no biggie - the default method name // has already been set. - if (! empty($segments)) { + if ($segments !== []) { $this->method = array_shift($segments) ?: $this->method; } @@ -115,7 +115,7 @@ public function getRoute(string $uri, string $httpVerb): array /** @var array $params An array of params to the controller method. */ $params = []; - if (! empty($segments)) { + if ($segments !== []) { $params = $segments; } diff --git a/system/Router/Router.php b/system/Router/Router.php index 0013d7cdf920..a4af03643e01 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -623,7 +623,7 @@ private function isValidSegment(string $segment): bool protected function setRequest(array $segments = []) { // If we don't have any segments - use the default controller; - if (empty($segments)) { + if ($segments === []) { return; } diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index abccfafb5ba4..7dc19de05a1a 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -125,7 +125,7 @@ public function open($path, $name): bool } } - if (empty($serverList)) { + if ($serverList === []) { $this->logger->error('Session: Memcached server pool is empty.'); return false; diff --git a/system/Session/Session.php b/system/Session/Session.php index 4e4a01581ba2..29516c006417 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -496,7 +496,7 @@ public function get(?string $key = null) return $value; } - if (empty($_SESSION)) { + if ($_SESSION === []) { return $key === null ? [] : null; } diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php index 100b14b72dff..a14183eeea92 100644 --- a/system/Test/DOMParser.php +++ b/system/Test/DOMParser.php @@ -213,7 +213,7 @@ protected function doXPath(?string $search, string $element, array $paths = []) // $paths might contain a number of different // ready to go xpath portions to tack on. - if (! empty($paths) && is_array($paths)) { + if ($paths !== [] && is_array($paths)) { foreach ($paths as $extra) { $path .= $extra; } diff --git a/system/Validation/DotArrayFilter.php b/system/Validation/DotArrayFilter.php index 43cb19370784..4f696886451d 100644 --- a/system/Validation/DotArrayFilter.php +++ b/system/Validation/DotArrayFilter.php @@ -93,7 +93,7 @@ private static function filter(array $indexes, array $array): array // If this is the last index, make sure to return it now, // and not try to recurse through things. - if (empty($indexes)) { + if ($indexes === []) { return [$currentIndex => $array[$currentIndex]]; } diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index eae6d961ce7d..6481a45b4e00 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -256,7 +256,7 @@ public function required($str = null): bool */ public function required_with($str = null, ?string $fields = null, array $data = []): bool { - if ($fields === null || empty($data)) { + if ($fields === null || $data === []) { throw new InvalidArgumentException('You must supply the parameters: fields, data.'); } @@ -283,7 +283,7 @@ public function required_with($str = null, ?string $fields = null, array $data = } } - return empty($requiredFields); + return $requiredFields === []; } /** @@ -305,7 +305,7 @@ public function required_without( ?string $error = null, ?string $field = null ): bool { - if ($otherFields === null || empty($data)) { + if ($otherFields === null || $data === []) { throw new InvalidArgumentException('You must supply the parameters: otherFields, data.'); } diff --git a/system/View/Parser.php b/system/View/Parser.php index ff729d4837d5..82ace74fba12 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -322,7 +322,7 @@ protected function parsePair(string $variable, array $data, string $template): a if (is_array($val)) { $pair = $this->parsePair($key, $val, $match[1]); - if (! empty($pair)) { + if ($pair !== []) { $pairs[array_keys($pair)[0]] = true; $temp = array_merge($temp, $pair); @@ -536,7 +536,7 @@ protected function prepareReplacement(array $matches, string $replace, bool $esc // so we need to break them apart so we can apply them all. $filters = ! empty($matches[1]) ? explode('|', $matches[1]) : []; - if ($escape && empty($filters) && ($context = $this->shouldAddEscaping($orig))) { + if ($escape && $filters === [] && ($context = $this->shouldAddEscaping($orig))) { $filters[] = "esc({$context})"; } @@ -604,7 +604,7 @@ protected function applyFilters(string $replace, array $filters): string } // Get our filter name - $filter = ! empty($param) ? trim(strtolower(substr($filter, 0, strpos($filter, '(')))) : trim($filter); + $filter = $param !== [] ? trim(strtolower(substr($filter, 0, strpos($filter, '(')))) : trim($filter); if (! array_key_exists($filter, $this->config->filters)) { continue; diff --git a/system/View/Plugins.php b/system/View/Plugins.php index 4b20caef8d3f..a842990dbbe1 100644 --- a/system/View/Plugins.php +++ b/system/View/Plugins.php @@ -79,7 +79,7 @@ public static function lang(array $params = []): string public static function ValidationErrors(array $params = []): string { $validator = Services::validation(); - if (empty($params)) { + if ($params === []) { return $validator->listErrors(); } diff --git a/system/View/Table.php b/system/View/Table.php index 5e241f11fefc..9a259c8beafa 100644 --- a/system/View/Table.php +++ b/system/View/Table.php @@ -312,7 +312,7 @@ public function generate($tableData = null) } // Is there anything to display? No? Smite them! - if (empty($this->heading) && empty($this->rows)) { + if (empty($this->heading) && $this->rows === []) { return 'Undefined table data'; } @@ -358,7 +358,7 @@ public function generate($tableData = null) } // Build the table rows - if (! empty($this->rows)) { + if ($this->rows !== []) { $out .= $this->template['tbody_open'] . $this->newline; $i = 1;