Skip to content

Commit cec682b

Browse files
committed
refactor: apply SimplifyEmptyCheckOnEmptyArrayRector
1 parent e9d1fcf commit cec682b

38 files changed

Lines changed: 78 additions & 78 deletions

‎system/Autoloader/FileLocator.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp =
196196
}
197197
}
198198

199-
if (! $prioritizeApp && ! empty($appPaths)) {
199+
if (! $prioritizeApp && $appPaths !== []) {
200200
$foundPaths = [...$foundPaths, ...$appPaths];
201201
}
202202

@@ -322,7 +322,7 @@ public function listFiles(string $path): array
322322

323323
$tempFiles = get_filenames($fullPath, true, false, false);
324324

325-
if (! empty($tempFiles)) {
325+
if ($tempFiles !== []) {
326326
$files = array_merge($files, $tempFiles);
327327
}
328328
}
@@ -356,7 +356,7 @@ public function listNamespaceFiles(string $prefix, string $path): array
356356

357357
$tempFiles = get_filenames($fullPath, true, false, false);
358358

359-
if (! empty($tempFiles)) {
359+
if ($tempFiles !== []) {
360360
$files = array_merge($files, $tempFiles);
361361
}
362362
}

‎system/BaseModel.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ public function insert($row = null, bool $returnID = true)
782782

783783
// doProtectFields() can further remove elements from
784784
// $row, so we need to check for empty dataset again
785-
if (! $this->allowEmptyInserts && empty($row)) {
785+
if (! $this->allowEmptyInserts && $row === []) {
786786
throw DataException::forEmptyDataset('insert');
787787
}
788788

@@ -964,7 +964,7 @@ public function update($id = null, $row = null): bool
964964

965965
// doProtectFields() can further remove elements from
966966
// $row, so we need to check for empty dataset again
967-
if (empty($row)) {
967+
if ($row === []) {
968968
throw DataException::forEmptyDataset('update');
969969
}
970970

@@ -1288,7 +1288,7 @@ protected function doProtectFields(array $row): array
12881288
return $row;
12891289
}
12901290

1291-
if (empty($this->allowedFields)) {
1291+
if ($this->allowedFields === []) {
12921292
throw DataException::forInvalidAllowedFields(static::class);
12931293
}
12941294

@@ -1510,7 +1510,7 @@ public function validate($row): bool
15101510
{
15111511
$rules = $this->getValidationRules();
15121512

1513-
if ($this->skipValidation || empty($rules) || empty($row)) {
1513+
if ($this->skipValidation || $rules === [] || empty($row)) {
15141514
return true;
15151515
}
15161516

@@ -1523,7 +1523,7 @@ public function validate($row): bool
15231523

15241524
// If no data existed that needs validation
15251525
// our job is done here.
1526-
if (empty($rules)) {
1526+
if ($rules === []) {
15271527
return true;
15281528
}
15291529

@@ -1879,7 +1879,7 @@ protected function fillPlaceholders(array $rules, array $data): array
18791879
$replacements['{' . $key . '}'] = $value;
18801880
}
18811881

1882-
if (! empty($replacements)) {
1882+
if ($replacements !== []) {
18831883
foreach ($rules as &$rule) {
18841884
if (is_array($rule)) {
18851885
foreach ($rule as &$row) {

‎system/CLI/BaseCommand.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function showHelp()
143143
} else {
144144
$usage = $this->name;
145145

146-
if (! empty($this->arguments)) {
146+
if ($this->arguments !== []) {
147147
$usage .= ' [arguments]';
148148
}
149149
}
@@ -156,7 +156,7 @@ public function showHelp()
156156
CLI::write($this->setPad($this->description, 0, 0, 2));
157157
}
158158

159-
if (! empty($this->arguments)) {
159+
if ($this->arguments !== []) {
160160
CLI::newLine();
161161
CLI::write(lang('CLI.helpArguments'), 'yellow');
162162
$length = max(array_map('strlen', array_keys($this->arguments)));
@@ -166,7 +166,7 @@ public function showHelp()
166166
}
167167
}
168168

169-
if (! empty($this->options)) {
169+
if ($this->options !== []) {
170170
CLI::newLine();
171171
CLI::write(lang('CLI.helpOptions'), 'yellow');
172172
$length = max(array_map('strlen', array_keys($this->options)));

‎system/CLI/CLI.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public static function prompt(string $field, $options = null, $validation = null
252252

253253
unset($opts[0]);
254254

255-
if (empty($opts)) {
255+
if ($opts === []) {
256256
$extraOutput = $extraOutputDefault;
257257
} else {
258258
$extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $opts) . ']';
@@ -324,7 +324,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
324324
$opts = $options;
325325
unset($opts[0]);
326326

327-
if (empty($opts)) {
327+
if ($opts === []) {
328328
$extraOutput = $extraOutputDefault;
329329
} else {
330330
$optsKey = [];
@@ -1000,7 +1000,7 @@ public static function getOptions(): array
10001000
*/
10011001
public static function getOptionString(bool $useLongOpts = false, bool $trim = false): string
10021002
{
1003-
if (empty(static::$options)) {
1003+
if (static::$options === []) {
10041004
return '';
10051005
}
10061006

@@ -1041,7 +1041,7 @@ public static function table(array $tbody, array $thead = [])
10411041
$tableRows = [];
10421042

10431043
// We need only indexes and not keys
1044-
if (! empty($thead)) {
1044+
if ($thead !== []) {
10451045
$tableRows[] = array_values($thead);
10461046
}
10471047

@@ -1115,7 +1115,7 @@ public static function table(array $tbody, array $thead = [])
11151115
$table .= '| ' . implode(' | ', $tableRows[$row]) . ' |' . PHP_EOL;
11161116

11171117
// Set the thead and table borders-bottom
1118-
if (($row === 0 && ! empty($thead)) || ($row + 1 === $totalRows)) {
1118+
if (($row === 0 && $thead !== []) || ($row + 1 === $totalRows)) {
11191119
$table .= $cols . PHP_EOL;
11201120
}
11211121
}

‎system/Controller.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function cachePage(int $time)
132132
*/
133133
protected function loadHelpers()
134134
{
135-
if (empty($this->helpers)) {
135+
if ($this->helpers === []) {
136136
return;
137137
}
138138

‎system/Database/BaseResult.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getCustomResultObject(string $className)
174174
*/
175175
public function getResultArray(): array
176176
{
177-
if (! empty($this->resultArray)) {
177+
if ($this->resultArray !== []) {
178178
return $this->resultArray;
179179
}
180180

@@ -214,7 +214,7 @@ public function getResultArray(): array
214214
*/
215215
public function getResultObject(): array
216216
{
217-
if (! empty($this->resultObject)) {
217+
if ($this->resultObject !== []) {
218218
return $this->resultObject;
219219
}
220220

@@ -323,7 +323,7 @@ public function getCustomRowObject(int $n, string $className)
323323
public function getRowArray(int $n = 0)
324324
{
325325
$result = $this->getResultArray();
326-
if (empty($result)) {
326+
if ($result === []) {
327327
return null;
328328
}
329329

@@ -344,7 +344,7 @@ public function getRowArray(int $n = 0)
344344
public function getRowObject(int $n = 0)
345345
{
346346
$result = $this->getResultObject();
347-
if (empty($result)) {
347+
if ($result === []) {
348348
return null;
349349
}
350350

@@ -392,7 +392,7 @@ public function getFirstRow(string $type = 'object')
392392
{
393393
$result = $this->getResult($type);
394394

395-
return (empty($result)) ? null : $result[0];
395+
return ($result === []) ? null : $result[0];
396396
}
397397

398398
/**
@@ -404,7 +404,7 @@ public function getLastRow(string $type = 'object')
404404
{
405405
$result = $this->getResult($type);
406406

407-
return (empty($result)) ? null : $result[count($result) - 1];
407+
return ($result === []) ? null : $result[count($result) - 1];
408408
}
409409

410410
/**
@@ -415,7 +415,7 @@ public function getLastRow(string $type = 'object')
415415
public function getNextRow(string $type = 'object')
416416
{
417417
$result = $this->getResult($type);
418-
if (empty($result)) {
418+
if ($result === []) {
419419
return null;
420420
}
421421

@@ -430,7 +430,7 @@ public function getNextRow(string $type = 'object')
430430
public function getPreviousRow(string $type = 'object')
431431
{
432432
$result = $this->getResult($type);
433-
if (empty($result)) {
433+
if ($result === []) {
434434
return null;
435435
}
436436

‎system/Database/MigrationRunner.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function latest(?string $group = null)
167167

168168
$migrations = $this->findMigrations();
169169

170-
if (empty($migrations)) {
170+
if ($migrations === []) {
171171
return true;
172172
}
173173

@@ -235,7 +235,7 @@ public function regress(int $targetBatch = 0, ?string $group = null)
235235
$targetBatch = $batches[count($batches) - 1 + $targetBatch] ?? 0;
236236
}
237237

238-
if (empty($batches) && $targetBatch === 0) {
238+
if ($batches === [] && $targetBatch === 0) {
239239
return true;
240240
}
241241

‎system/Database/MySQLi/Builder.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Builder extends BaseBuilder
4949
*/
5050
protected function _fromTables(): string
5151
{
52-
if (! empty($this->QBJoin) && count($this->QBFrom) > 1) {
52+
if ($this->QBJoin !== [] && count($this->QBFrom) > 1) {
5353
return '(' . implode(', ', $this->QBFrom) . ')';
5454
}
5555

‎system/Database/SQLSRV/Builder.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function replace(?array $set = null)
332332
$this->set($set);
333333
}
334334

335-
if (empty($this->QBSet)) {
335+
if ($this->QBSet === []) {
336336
if ($this->db->DBDebug) {
337337
throw new DatabaseException('You must use the "set" method to update an entry.');
338338
}
@@ -514,7 +514,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
514514
$this->where($where);
515515
}
516516

517-
if (empty($this->QBWhere)) {
517+
if ($this->QBWhere === []) {
518518
if ($this->db->DBDebug) {
519519
throw new DatabaseException('Deletes are not allowed unless they contain a "where" or "like" clause.');
520520
}
@@ -551,7 +551,7 @@ protected function compileSelect($selectOverride = false): string
551551
$sql = (! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT ';
552552

553553
// SQL Server can't work with select * if group by is specified
554-
if (empty($this->QBSelect) && ! empty($this->QBGroupBy) && is_array($this->QBGroupBy)) {
554+
if (empty($this->QBSelect) && $this->QBGroupBy !== [] && is_array($this->QBGroupBy)) {
555555
foreach ($this->QBGroupBy as $field) {
556556
$this->QBSelect[] = is_array($field) ? $field['field'] : $field;
557557
}
@@ -573,7 +573,7 @@ protected function compileSelect($selectOverride = false): string
573573
}
574574

575575
// Write the "FROM" portion of the query
576-
if (! empty($this->QBFrom)) {
576+
if ($this->QBFrom !== []) {
577577
$sql .= "\nFROM " . $this->_fromTables();
578578
}
579579

@@ -660,7 +660,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
660660
});
661661

662662
// if no primary found then look for unique - since indexes have no order
663-
if (empty($uniqueIndexes)) {
663+
if ($uniqueIndexes === []) {
664664
$uniqueIndexes = array_filter($tableIndexes, static function ($index) use ($fieldNames) {
665665
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
666666

‎system/Database/SQLSRV/Forge.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function _alterTable(string $alterType, string $table, $field)
145145
$fld = array_intersect($field, $index->fields);
146146

147147
// Drop index if field is part of an index
148-
if (! empty($fld)) {
148+
if ($fld !== []) {
149149
$this->_dropIndex($table, $index);
150150
}
151151
}

0 commit comments

Comments
 (0)