Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function run(array $params)
{
$name = array_shift($params);

if (empty($name)) {
if ($name === null || $name === '') {
$name = CLI::prompt('Database name', null, 'required'); // @codeCoverageIgnore
}

Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function run(array $params)

$migrations = $runner->findNamespaceMigrations($namespace);

if (empty($migrations)) {
if ($migrations === []) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function run(array $params)
$seeder = new Seeder(new Database());
$seedName = array_shift($params);

if (empty($seedName)) {
if ($seedName === null || $seedName === '') {
$seedName = CLI::prompt(lang('Migrations.migSeeder'), null, 'required'); // @codeCoverageIgnore
}

Expand Down
4 changes: 2 additions & 2 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ protected static function getSharedInstance(string $key, ...$params)
public static function autoloader(bool $getShared = true)
{
if ($getShared) {
if (empty(static::$instances['autoloader'])) {
if (! isset(static::$instances['autoloader'])) {
static::$instances['autoloader'] = new Autoloader();
}

Expand All @@ -296,7 +296,7 @@ public static function autoloader(bool $getShared = true)
public static function locator(bool $getShared = true)
{
if ($getShared) {
if (empty(static::$instances['locator'])) {
if (! isset(static::$instances['locator'])) {
$cacheEnabled = class_exists(Optimize::class)
&& (new Optimize())->locatorCacheEnabled;

Expand Down
4 changes: 2 additions & 2 deletions system/Config/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ protected function setVariable(string $name, string $value = '')
putenv("{$name}={$value}");
}

if (empty($_ENV[$name])) {
if (! isset($_ENV[$name]) || in_array($_ENV[$name], ['', '0'], true)) {
$_ENV[$name] = $value;
}

if (empty($_SERVER[$name])) {
if (! isset($_SERVER[$name]) || in_array($_SERVER[$name], ['', '0'], true)) {
$_SERVER[$name] = $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static function email($config = null, bool $getShared = true)
return static::getSharedInstance('email', $config);
}

if (empty($config) || (! is_array($config) && ! $config instanceof EmailConfig)) {
if (! $config instanceof EmailConfig && (! is_array($config) || $config === [])) {
$config = config(EmailConfig::class);
}

Expand Down
54 changes: 27 additions & 27 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class BaseBuilder
*/
public function __construct($tableName, ConnectionInterface $db, ?array $options = null)
{
if (empty($tableName)) {
if (in_array($tableName, ['', '0', []], true)) {
throw new DatabaseException('A table must be specified when creating a new Query Builder.');
}

Expand Down Expand Up @@ -769,7 +769,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
$escape = $this->db->protectIdentifiers;
}

$prefix = empty($this->{$qbKey}) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = $this->{$qbKey} === [] ? $this->groupGetType('') : $this->groupGetType($type);

foreach ($keyValue as $k => $v) {
if ($rawSqlOnly) {
Expand All @@ -778,7 +778,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
} elseif ($v !== null) {
$op = $this->getOperatorFromWhereKey($k);

if (! empty($op)) {
if ($op !== false && $op !== []) {
$k = trim($k);

end($op);
Expand Down Expand Up @@ -985,7 +985,7 @@ protected function _whereIn(?string $key = null, $values = null, bool $not = fal

$ok = $this->setBind($ok, $whereIn, $escape);

$prefix = empty($this->{$clause}) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = $this->{$clause} === [] ? $this->groupGetType('') : $this->groupGetType($type);

$whereIn = [
'condition' => "{$prefix}{$key}{$not} IN :{$ok}:",
Expand Down Expand Up @@ -1125,7 +1125,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri
$v = $match;
$insensitiveSearch = false;

$prefix = empty($this->{$clause}) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = $this->{$clause} === [] ? $this->groupGetType('') : $this->groupGetType($type);

if ($side === 'none') {
$bind = $this->setBind($field->getBindingKey(), $v, $escape);
Expand Down Expand Up @@ -1357,7 +1357,7 @@ protected function groupStartPrepare(string $not = '', string $type = 'AND ', st
$type = $this->groupGetType($type);

$this->QBWhereGroupStarted = true;
$prefix = empty($this->{$clause}) ? '' : $type;
$prefix = $this->{$clause} === [] ? '' : $type;
$where = [
'condition' => $prefix . $not . str_repeat(' ', ++$this->QBWhereGroupCount) . ' (',
'escape' => false,
Expand Down Expand Up @@ -1626,7 +1626,7 @@ protected function compileFinalQuery(string $sql): string
$query = new Query($this->db);
$query->setQuery($sql, $this->binds, false);

if (! empty($this->db->swapPre) && ! empty($this->db->DBPrefix)) {
if ($this->db->swapPre !== '' && $this->db->DBPrefix !== '') {
$query->swapPrefix($this->db->DBPrefix, $this->db->swapPre);
}

Expand Down Expand Up @@ -1683,7 +1683,7 @@ public function countAll(bool $reset = true)

$query = $this->db->query($sql, null, false);

if (empty($query->getResult())) {
if ($query->getResult() === []) {
return 0;
}

Expand All @@ -1709,7 +1709,7 @@ public function countAllResults(bool $reset = true)
// for selecting COUNT(*) ...
$orderBy = [];

if (! empty($this->QBOrderBy)) {
if (is_array($this->QBOrderBy) && $this->QBOrderBy !== []) {
$orderBy = $this->QBOrderBy;

$this->QBOrderBy = null;
Expand All @@ -1720,7 +1720,7 @@ public function countAllResults(bool $reset = true)

$this->QBLimit = false;

if ($this->QBDistinct === true || ! empty($this->QBGroupBy)) {
if ($this->QBDistinct === true || $this->QBGroupBy !== []) {
// We need to backup the original SELECT in case DBPrefix is used
$select = $this->QBSelect;
$sql = $this->countString . $this->db->protectIdentifiers('numrows') . "\nFROM (\n" . $this->compileSelect() . "\n) CI_count_all_results";
Expand Down Expand Up @@ -1749,7 +1749,7 @@ public function countAllResults(bool $reset = true)

$row = $result instanceof ResultInterface ? $result->getRow() : null;

if (empty($row)) {
if ($row === null) {
return 0;
}

Expand Down Expand Up @@ -1813,7 +1813,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
*/
protected function batchExecute(string $renderMethod, int $batchSize = 100)
{
if (empty($this->QBSet)) {
if ($this->QBSet === []) {
if ($this->db->DBDebug) {
throw new DatabaseException(trim($renderMethod, '_') . '() has no data.');
}
Expand Down Expand Up @@ -1866,7 +1866,7 @@ protected function batchExecute(string $renderMethod, int $batchSize = 100)
*/
public function setData($set, ?bool $escape = null, string $alias = '')
{
if (empty($set)) {
if ($set === []) {
if ($this->db->DBDebug) {
throw new DatabaseException('setData() has no data.');
}
Expand Down Expand Up @@ -2073,7 +2073,7 @@ private function setAlias(string $alias): BaseBuilder
*/
public function updateFields($set, bool $addToDefault = false, ?array $ignore = null)
{
if (! empty($set)) {
if (! in_array($set, [null, [], ''], true)) {
if (! is_array($set)) {
$set = explode(',', $set);
}
Expand Down Expand Up @@ -2109,13 +2109,13 @@ public function updateFields($set, bool $addToDefault = false, ?array $ignore =
/**
* Sets constraints for batch upsert, update
*
* @param array|RawSql|string $set a string of columns, key value pairs, or RawSql
* @param array|RawSql|string|null $set A string of columns, key value pairs, or RawSql
*
* @return $this
*/
public function onConstraint($set)
{
if (! empty($set)) {
if (! in_array($set, [null, [], ''], true)) {
if (is_string($set)) {
$set = explode(',', $set);

Expand Down Expand Up @@ -2388,7 +2388,7 @@ protected function removeAlias(string $from): string
*/
protected function validateInsert(): bool
{
if (empty($this->QBSet)) {
if ($this->QBSet === []) {
if ($this->db->DBDebug) {
throw new DatabaseException('You must use the "set" method to insert an entry.');
}
Expand Down Expand Up @@ -2424,7 +2424,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.');
}
Expand Down Expand Up @@ -2576,7 +2576,7 @@ protected function _update(string $table, array $values): string
*/
protected function validateUpdate(): bool
{
if (empty($this->QBSet)) {
if ($this->QBSet === []) {
if ($this->db->DBDebug) {
throw new DatabaseException('You must use the "set" method to update an entry.');
}
Expand Down Expand Up @@ -2827,7 +2827,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.');
}
Expand All @@ -2846,7 +2846,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
$this->QBLimit = $limit;
}

if (! empty($this->QBLimit)) {
if ($this->QBLimit !== false && $this->QBLimit !== 0) {
if (! $this->canLimitDeletes) {
throw new DatabaseException('SQLite3 does not allow LIMITs on DELETE queries.');
}
Expand Down Expand Up @@ -3105,7 +3105,7 @@ protected function compileSelect($selectOverride = false): string
} else {
$sql = $this->QBDistinct ? 'SELECT DISTINCT ' : 'SELECT ';

if (empty($this->QBSelect)) {
if ($this->QBSelect === []) {
$sql .= '*';
} else {
// Cycle through the "select" portion of the query and prep each column name.
Expand All @@ -3124,11 +3124,11 @@ protected function compileSelect($selectOverride = false): string
}
}

if (! empty($this->QBFrom)) {
if ($this->QBFrom !== []) {
$sql .= "\nFROM " . $this->_fromTables();
}

if (! empty($this->QBJoin)) {
if ($this->QBJoin !== []) {
$sql .= "\n" . implode("\n", $this->QBJoin);
}

Expand Down Expand Up @@ -3177,7 +3177,7 @@ protected function compileIgnore(string $statement)
*/
protected function compileWhereHaving(string $qbKey): string
{
if (! empty($this->{$qbKey})) {
if ($this->{$qbKey} !== []) {
foreach ($this->{$qbKey} as &$qbkey) {
// Is this condition already compiled?
if (is_string($qbkey)) {
Expand Down Expand Up @@ -3266,7 +3266,7 @@ protected function compileWhereHaving(string $qbKey): string
*/
protected function compileGroupBy(): string
{
if (! empty($this->QBGroupBy)) {
if ($this->QBGroupBy !== []) {
foreach ($this->QBGroupBy as &$groupBy) {
// Is it already compiled?
if (is_string($groupBy)) {
Expand Down Expand Up @@ -3453,7 +3453,7 @@ protected function resetSelect()
}

// Reset QBFrom part
if (! empty($this->QBFrom)) {
if ($this->QBFrom !== []) {
$this->from(array_shift($this->QBFrom), true);
}
}
Expand Down
Loading
Loading