Skip to content

Commit 69fbb6c

Browse files
committed
refactor: replace empty()
1 parent 479b35d commit 69fbb6c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

system/Model.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ protected function doFirst()
257257

258258
if ($this->tempUseSoftDeletes) {
259259
$builder->where($this->table . '.' . $this->deletedField, null);
260-
} elseif ($this->useSoftDeletes && empty($builder->QBGroupBy) && $this->primaryKey) {
260+
} elseif ($this->useSoftDeletes && ($builder->QBGroupBy === []) && $this->primaryKey) {
261261
$builder->groupBy($this->table . '.' . $this->primaryKey);
262262
}
263263

264264
// Some databases, like PostgreSQL, need order
265265
// information to consistently return correct results.
266-
if ($builder->QBGroupBy && empty($builder->QBOrderBy) && $this->primaryKey) {
266+
if ($builder->QBGroupBy && ($builder->QBOrderBy === []) && $this->primaryKey) {
267267
$builder->orderBy($this->table . '.' . $this->primaryKey, 'asc');
268268
}
269269

@@ -286,7 +286,7 @@ protected function doInsert(array $row)
286286

287287
// Require non-empty primaryKey when
288288
// not using auto-increment feature
289-
if (! $this->useAutoIncrement && empty($row[$this->primaryKey])) {
289+
if (! $this->useAutoIncrement && ! isset($row[$this->primaryKey])) {
290290
throw DataException::forEmptyPrimaryKey('insert');
291291
}
292292

@@ -351,7 +351,7 @@ protected function doInsertBatch(?array $set = null, ?bool $escape = null, int $
351351
foreach ($set as $row) {
352352
// Require non-empty primaryKey when
353353
// not using auto-increment feature
354-
if (! $this->useAutoIncrement && empty($row[$this->primaryKey])) {
354+
if (! $this->useAutoIncrement && ! isset($row[$this->primaryKey])) {
355355
throw DataException::forEmptyPrimaryKey('insertBatch');
356356
}
357357
}
@@ -433,7 +433,7 @@ protected function doDelete($id = null, bool $purge = false)
433433
}
434434

435435
if ($this->useSoftDeletes && ! $purge) {
436-
if (empty($builder->getCompiledQBWhere())) {
436+
if ($builder->getCompiledQBWhere() === []) {
437437
throw new DatabaseException(
438438
'Deletes are not allowed unless they contain a "where" or "like" clause.'
439439
);
@@ -557,7 +557,7 @@ public function getIdValue($row)
557557
return $row->{$this->primaryKey};
558558
}
559559

560-
if (is_array($row) && ! empty($row[$this->primaryKey])) {
560+
if (is_array($row) && isset($row[$this->primaryKey])) {
561561
return $row[$this->primaryKey];
562562
}
563563

@@ -591,7 +591,7 @@ public function chunk(int $size, Closure $userFunc)
591591

592592
$offset += $size;
593593

594-
if (empty($rows)) {
594+
if ($rows === []) {
595595
continue;
596596
}
597597

@@ -648,7 +648,7 @@ public function builder(?string $table = null)
648648
// We're going to force a primary key to exist
649649
// so we don't have overly convoluted code,
650650
// and future features are likely to require them.
651-
if (empty($this->primaryKey)) {
651+
if ($this->primaryKey === '') {
652652
throw ModelException::forNoPrimaryKey(static::class);
653653
}
654654

@@ -729,8 +729,8 @@ protected function shouldUpdate($row): bool
729729
*/
730730
public function insert($row = null, bool $returnID = true)
731731
{
732-
if (! empty($this->tempData['data'])) {
733-
if (empty($row)) {
732+
if (isset($this->tempData['data'])) {
733+
if ($row === null) {
734734
$row = $this->tempData['data'];
735735
} else {
736736
$row = $this->transformDataToArray($row, 'insert');
@@ -792,8 +792,8 @@ protected function doProtectFieldsForInsert(array $row): array
792792
*/
793793
public function update($id = null, $row = null): bool
794794
{
795-
if (! empty($this->tempData['data'])) {
796-
if (empty($row)) {
795+
if (isset($this->tempData['data'])) {
796+
if ($row === null) {
797797
$row = $this->tempData['data'];
798798
} else {
799799
$row = $this->transformDataToArray($row, 'update');
@@ -910,7 +910,7 @@ public static function classToArray($data, $primaryKey = null, string $dateForma
910910
$properties = $data->toRawArray($onlyChanged);
911911

912912
// Always grab the primary key otherwise updates will fail.
913-
if (! empty($properties) && ! empty($primaryKey) && ! in_array($primaryKey, $properties, true) && ! empty($data->{$primaryKey})) {
913+
if ($properties !== [] && isset($primaryKey) && ! in_array($primaryKey, $properties, true) && isset($data->{$primaryKey})) {
914914
$properties[$primaryKey] = $data->{$primaryKey};
915915
}
916916
} else {

system/Session/Session.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function start()
241241
$this->startSession();
242242

243243
// Is session ID auto-regeneration configured? (ignoring ajax requests)
244-
if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
244+
if ((! isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
245245
&& ($regenerateTime = $this->config->timeToUpdate) > 0
246246
) {
247247
if (! isset($_SESSION['__ci_last_regenerate'])) {
@@ -368,7 +368,7 @@ protected function configureSidLength()
368368
*/
369369
protected function initVars()
370370
{
371-
if (empty($_SESSION['__ci_vars'])) {
371+
if (! isset($_SESSION['__ci_vars'])) {
372372
return;
373373
}
374374

@@ -384,7 +384,7 @@ protected function initVars()
384384
}
385385
}
386386

387-
if (empty($_SESSION['__ci_vars'])) {
387+
if ($_SESSION['__ci_vars'] === []) {
388388
unset($_SESSION['__ci_vars']);
389389
}
390390
}
@@ -646,7 +646,7 @@ public function getFlashdata(?string $key = null)
646646

647647
$flashdata = [];
648648

649-
if (! empty($_SESSION['__ci_vars'])) {
649+
if (isset($_SESSION['__ci_vars'])) {
650650
foreach ($_SESSION['__ci_vars'] as $key => &$value) {
651651
if (! is_int($value)) {
652652
$flashdata[$key] = $_SESSION[$key];
@@ -706,7 +706,7 @@ public function markAsFlashdata($key): bool
706706
*/
707707
public function unmarkFlashdata($key)
708708
{
709-
if (empty($_SESSION['__ci_vars'])) {
709+
if (! isset($_SESSION['__ci_vars'])) {
710710
return;
711711
}
712712

@@ -720,7 +720,7 @@ public function unmarkFlashdata($key)
720720
}
721721
}
722722

723-
if (empty($_SESSION['__ci_vars'])) {
723+
if ($_SESSION['__ci_vars'] === []) {
724724
unset($_SESSION['__ci_vars']);
725725
}
726726
}
@@ -778,7 +778,7 @@ public function getTempdata(?string $key = null)
778778

779779
$tempdata = [];
780780

781-
if (! empty($_SESSION['__ci_vars'])) {
781+
if (isset($_SESSION['__ci_vars'])) {
782782
foreach ($_SESSION['__ci_vars'] as $key => &$value) {
783783
if (is_int($value)) {
784784
$tempdata[$key] = $_SESSION[$key];
@@ -856,7 +856,7 @@ public function markAsTempdata($key, int $ttl = 300): bool
856856
*/
857857
public function unmarkTempdata($key)
858858
{
859-
if (empty($_SESSION['__ci_vars'])) {
859+
if (! isset($_SESSION['__ci_vars'])) {
860860
return;
861861
}
862862

@@ -870,7 +870,7 @@ public function unmarkTempdata($key)
870870
}
871871
}
872872

873-
if (empty($_SESSION['__ci_vars'])) {
873+
if ($_SESSION['__ci_vars'] === []) {
874874
unset($_SESSION['__ci_vars']);
875875
}
876876
}

0 commit comments

Comments
 (0)