Skip to content

Commit 5e107ef

Browse files
committed
refactor: apply DisallowedEmptyRuleFixerRector
1 parent 3433509 commit 5e107ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+97
-97
lines changed

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function respond($data = null, ?int $status = null, string $message =
9494
$output = null;
9595
$this->format($data);
9696
} else {
97-
$status = empty($status) ? 200 : $status;
97+
$status = $status === null || $status === 0 ? 200 : $status;
9898
$output = $this->format($data);
9999
}
100100

system/Autoloader/FileLocator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
5151
$file = $this->ensureExt($file, $ext);
5252

5353
// Clears the folder name if it is at the beginning of the filename
54-
if (! empty($folder) && strpos($file, $folder) === 0) {
54+
if ($folder !== null && $folder !== '' && $folder !== '0' && strpos($file, $folder) === 0) {
5555
$file = substr($file, strlen($folder . '/'));
5656
}
5757

@@ -101,7 +101,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
101101
// If we have a folder name, then the calling function
102102
// expects this file to be within that folder, like 'Views',
103103
// or 'libraries'.
104-
if (! empty($folder) && strpos($path . $filename, '/' . $folder . '/') === false) {
104+
if ($folder !== null && $folder !== '' && $folder !== '0' && strpos($path . $filename, '/' . $folder . '/') === false) {
105105
$path .= trim($folder, '/') . '/';
106106
}
107107

@@ -154,7 +154,7 @@ public function getClassname(string $file): string
154154
}
155155
}
156156

157-
if (empty($className)) {
157+
if ($className === '' || $className === '0') {
158158
return '';
159159
}
160160

@@ -305,7 +305,7 @@ public function findQualifiedNameFromPath(string $path)
305305
*/
306306
public function listFiles(string $path): array
307307
{
308-
if (empty($path)) {
308+
if ($path === '' || $path === '0') {
309309
return [];
310310
}
311311

@@ -338,7 +338,7 @@ public function listFiles(string $path): array
338338
*/
339339
public function listNamespaceFiles(string $prefix, string $path): array
340340
{
341-
if (empty($path) || empty($prefix)) {
341+
if ($path === '' || $path === '0' || ($prefix === '' || $prefix === '0')) {
342342
return [];
343343
}
344344

@@ -372,7 +372,7 @@ public function listNamespaceFiles(string $prefix, string $path): array
372372
*/
373373
protected function legacyLocate(string $file, ?string $folder = null)
374374
{
375-
$path = APPPATH . (empty($folder) ? $file : $folder . '/' . $file);
375+
$path = APPPATH . ($folder === null || $folder === '' || $folder === '0' ? $file : $folder . '/' . $file);
376376
$path = realpath($path) ?: $path;
377377

378378
if (is_file($path)) {

system/BaseModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ public function getValidationMessages(): array
15791579
*/
15801580
protected function cleanValidationRules(array $rules, ?array $row = null): array
15811581
{
1582-
if (empty($row)) {
1582+
if ($row === null || $row === []) {
15831583
return [];
15841584
}
15851585

@@ -1795,7 +1795,7 @@ protected function transformDataToArray($row, string $type): array
17951795
}
17961796

17971797
// If it's still empty here, means $row is no change or is empty object
1798-
if (! $this->allowEmptyInserts && empty($row)) {
1798+
if (! $this->allowEmptyInserts && ($row === null || $row === [])) {
17991799
throw DataException::forEmptyDataset($type);
18001800
}
18011801

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
849849
*/
850850
public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string
851851
{
852-
if (empty($string)) {
852+
if ($string === null || $string === '' || $string === '0') {
853853
return '';
854854
}
855855

system/Cache/CacheFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public static function getHandler(Cache $config, ?string $handler = null, ?strin
5252
throw CacheException::forNoBackup();
5353
}
5454

55-
$handler = ! empty($handler) ? $handler : $config->handler;
56-
$backup = ! empty($backup) ? $backup : $config->backupHandler;
55+
$handler = $handler !== null && $handler !== '' && $handler !== '0' ? $handler : $config->handler;
56+
$backup = $backup !== null && $backup !== '' && $backup !== '0' ? $backup : $config->backupHandler;
5757

5858
if (! array_key_exists($handler, $config->validHandlers) || ! array_key_exists($backup, $config->validHandlers)) {
5959
throw CacheException::forHandlerNotFound();

system/Common.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function csrf_hash(): string
291291
*/
292292
function csrf_field(?string $id = null): string
293293
{
294-
return '<input type="hidden"' . (! empty($id) ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>';
294+
return '<input type="hidden"' . ($id !== null && $id !== '' && $id !== '0' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>';
295295
}
296296
}
297297

@@ -301,7 +301,7 @@ function csrf_field(?string $id = null): string
301301
*/
302302
function csrf_meta(?string $id = null): string
303303
{
304-
return '<meta' . (! empty($id) ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>';
304+
return '<meta' . ($id !== null && $id !== '' && $id !== '0' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>';
305305
}
306306
}
307307

@@ -856,7 +856,7 @@ function redirect(?string $route = null): RedirectResponse
856856
{
857857
$response = Services::redirectresponse(null, true);
858858

859-
if (! empty($route)) {
859+
if ($route !== null && $route !== '' && $route !== '0') {
860860
return $response->route($route);
861861
}
862862

@@ -1129,7 +1129,7 @@ function timer(?string $name = null, ?callable $callable = null)
11291129
{
11301130
$timer = Services::timer();
11311131

1132-
if (empty($name)) {
1132+
if ($name === null || $name === '' || $name === '0') {
11331133
return $timer;
11341134
}
11351135

system/Database/BaseBuilder.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function __construct($tableName, ConnectionInterface $db, ?array $options
318318

319319
$this->from($tableName);
320320

321-
if (! empty($options)) {
321+
if ($options !== null && $options !== []) {
322322
foreach ($options as $key => $value) {
323323
if (property_exists($this, $key)) {
324324
$this->{$key} = $value;
@@ -928,7 +928,7 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
928928
*/
929929
protected function _whereIn(?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null, string $clause = 'QBWhere')
930930
{
931-
if (empty($key) || ! is_string($key)) {
931+
if ($key === null || $key === '' || $key === '0' || ! is_string($key)) {
932932
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
933933
}
934934

@@ -1434,7 +1434,7 @@ public function orHaving($key, $value = null, ?bool $escape = null)
14341434
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
14351435
{
14361436
$qbOrderBy = [];
1437-
if (empty($orderBy)) {
1437+
if ($orderBy === '' || $orderBy === '0') {
14381438
return $this;
14391439
}
14401440

@@ -1490,7 +1490,7 @@ public function limit(?int $value = null, ?int $offset = 0)
14901490
$this->QBLimit = $value;
14911491
}
14921492

1493-
if (! empty($offset)) {
1493+
if ($offset !== null && $offset !== 0) {
14941494
$this->QBOffset = $offset;
14951495
}
14961496

@@ -1504,7 +1504,7 @@ public function limit(?int $value = null, ?int $offset = 0)
15041504
*/
15051505
public function offset(int $offset)
15061506
{
1507-
if (! empty($offset)) {
1507+
if ($offset !== 0) {
15081508
$this->QBOffset = (int) $offset;
15091509
}
15101510

@@ -1736,7 +1736,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
17361736
$this->where($where);
17371737
}
17381738

1739-
if (! empty($limit)) {
1739+
if ($limit !== null && $limit !== 0) {
17401740
$this->limit($limit, $offset);
17411741
}
17421742

@@ -2452,7 +2452,7 @@ public function update($set = null, $where = null, ?int $limit = null): bool
24522452
$this->where($where);
24532453
}
24542454

2455-
if (! empty($limit)) {
2455+
if ($limit !== null && $limit !== 0) {
24562456
if (! $this->canLimitWhereUpdates) {
24572457
throw new DatabaseException('This driver does not allow LIMITs on UPDATE queries using WHERE.');
24582458
}
@@ -2762,7 +2762,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
27622762

27632763
$sql = $this->_delete($this->removeAlias($table));
27642764

2765-
if (! empty($limit)) {
2765+
if ($limit !== null && $limit !== 0) {
27662766
$this->QBLimit = $limit;
27672767
}
27682768

@@ -3172,7 +3172,7 @@ protected function compileGroupBy(): string
31723172
*/
31733173
protected function compileOrderBy(): string
31743174
{
3175-
if (is_array($this->QBOrderBy) && ! empty($this->QBOrderBy)) {
3175+
if (is_array($this->QBOrderBy) && $this->QBOrderBy !== []) {
31763176
foreach ($this->QBOrderBy as &$orderBy) {
31773177
if ($orderBy['escape'] !== false && ! $this->isLiteral($orderBy['field'])) {
31783178
$orderBy['field'] = $this->db->protectIdentifiers($orderBy['field']);
@@ -3265,10 +3265,10 @@ protected function isLiteral(string $str): bool
32653265
{
32663266
$str = trim($str);
32673267

3268-
if (empty($str)
3269-
|| ctype_digit($str)
3270-
|| (string) (float) $str === $str
3271-
|| in_array(strtoupper($str), ['TRUE', 'FALSE'], true)
3268+
if ($str === '' || $str === '0'
3269+
|| ctype_digit($str)
3270+
|| (string) (float) $str === $str
3271+
|| in_array(strtoupper($str), ['TRUE', 'FALSE'], true)
32723272
) {
32733273
return true;
32743274
}

system/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function parseDSN(array $params): array
104104
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : '',
105105
];
106106

107-
if (! empty($dsn['query'])) {
107+
if (isset($dsn['query']) && ($dsn['query'] !== '' && $dsn['query'] !== '0')) {
108108
parse_str($dsn['query'], $extra);
109109

110110
foreach ($extra as $key => $val) {

system/Database/MigrationRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public function getHistory(string $group = 'default'): array
639639
$builder = $this->db->table($this->table);
640640

641641
// If group was specified then use it
642-
if (! empty($group)) {
642+
if ($group !== '' && $group !== '0') {
643643
$builder->where('group', $group);
644644
}
645645

system/Database/MySQLi/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function connect(bool $persistent = false)
150150
$ssl['cipher'] = $this->encrypt['ssl_cipher'];
151151
}
152152

153-
if (! empty($ssl)) {
153+
if ($ssl !== []) {
154154
if (isset($this->encrypt['ssl_verify'])) {
155155
if ($this->encrypt['ssl_verify']) {
156156
if (defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT')) {

system/Database/OCI8/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected function _truncate(string $table): string
166166
*/
167167
public function delete($where = '', ?int $limit = null, bool $resetData = true)
168168
{
169-
if (! empty($limit)) {
169+
if ($limit !== null && $limit !== 0) {
170170
$this->QBLimit = $limit;
171171
}
172172

system/Database/Postgre/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
229229
*/
230230
public function delete($where = '', ?int $limit = null, bool $resetData = true)
231231
{
232-
if (! empty($limit) || ! empty($this->QBLimit)) {
232+
if ($limit !== null && $limit !== 0 || ! empty($this->QBLimit)) {
233233
throw new DatabaseException('PostgreSQL does not allow LIMITs on DELETE queries.');
234234
}
235235

system/Database/SQLSRV/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
522522
return false; // @codeCoverageIgnore
523523
}
524524

525-
if (! empty($limit)) {
525+
if ($limit !== null && $limit !== 0) {
526526
$this->QBLimit = $limit;
527527
}
528528

system/Database/SQLSRV/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public function affectedRows(): int
444444
*/
445445
public function setDatabase(?string $databaseName = null)
446446
{
447-
if (empty($databaseName)) {
447+
if ($databaseName === null || $databaseName === '' || $databaseName === '0') {
448448
$databaseName = $this->database;
449449
}
450450

@@ -538,7 +538,7 @@ public function getVersion(): string
538538
return $this->dataCache['version'];
539539
}
540540

541-
if (! $this->connID || empty($info = sqlsrv_server_info($this->connID))) {
541+
if (! $this->connID || ($info = sqlsrv_server_info($this->connID)) === []) {
542542
$this->initialize();
543543
}
544544

system/Database/Seeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function __construct(Database $config, ?BaseConnection $db = null)
7878
{
7979
$this->seedPath = $config->filesPath ?? APPPATH . 'Database/';
8080

81-
if (empty($this->seedPath)) {
81+
if ($this->seedPath === '' || $this->seedPath === '0') {
8282
throw new InvalidArgumentException('Invalid filesPath set in the Config\Database.');
8383
}
8484

system/Debug/BaseExceptionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected static function describeMemory(int $bytes): string
161161
*/
162162
protected static function highlightFile(string $file, int $lineNumber, int $lines = 15)
163163
{
164-
if (empty($file) || ! is_readable($file)) {
164+
if ($file === '' || $file === '0' || ! is_readable($file)) {
165165
return false;
166166
}
167167

system/Debug/Exceptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public static function describeMemory(int $bytes): string
522522
*/
523523
public static function highlightFile(string $file, int $lineNumber, int $lines = 15)
524524
{
525-
if (empty($file) || ! is_readable($file)) {
525+
if ($file === '' || $file === '0' || ! is_readable($file)) {
526526
return false;
527527
}
528528

system/Email/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,13 +1236,13 @@ protected function buildMessage()
12361236
. $this->prepQuotedPrintable($this->body) . $this->newline . $this->newline
12371237
. '--' . $altBoundary . '--' . $this->newline . $this->newline;
12381238

1239-
if (! empty($relBoundary)) {
1239+
if ($relBoundary !== '' && $relBoundary !== '0') {
12401240
$body .= $this->newline . $this->newline;
12411241
$this->appendAttachments($body, $relBoundary, 'related');
12421242
}
12431243

12441244
// multipart/mixed attachments
1245-
if (! empty($atcBoundary)) {
1245+
if ($atcBoundary !== '' && $atcBoundary !== '0') {
12461246
$body .= $this->newline . $this->newline;
12471247
$this->appendAttachments($body, $atcBoundary, 'mixed');
12481248
}

system/HTTP/CLIRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getPath(): string
9595
{
9696
$path = implode('/', $this->segments);
9797

98-
return empty($path) ? '' : $path;
98+
return $path === '' || $path === '0' ? '' : $path;
9999
}
100100

101101
/**

system/HTTP/ContentSecurityPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ protected function addToHeader(string $name, $values = null)
790790
$reportSources = [];
791791

792792
foreach ($values as $value => $reportOnly) {
793-
if (is_numeric($value) && is_string($reportOnly) && ! empty($reportOnly)) {
793+
if (is_numeric($value) && is_string($reportOnly) && ($reportOnly !== '' && $reportOnly !== '0')) {
794794
$value = $reportOnly;
795795
$reportOnly = $this->reportOnly;
796796
}

system/HTTP/IncomingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected function detectURI(string $protocol, string $baseURL)
256256
*/
257257
public function detectPath(string $protocol = ''): string
258258
{
259-
if (empty($protocol)) {
259+
if ($protocol === '' || $protocol === '0') {
260260
$protocol = 'REQUEST_URI';
261261
}
262262

system/HTTP/Negotiate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function charset(array $supported): string
9393

9494
// If no charset is shown as a match, ignore the directive
9595
// as allowed by the RFC, and tell it a default value.
96-
if (empty($match)) {
96+
if ($match === '' || $match === '0') {
9797
return 'utf-8';
9898
}
9999

@@ -158,7 +158,7 @@ protected function getBestMatch(
158158
throw HTTPException::forEmptySupportedNegotiations();
159159
}
160160

161-
if (empty($header)) {
161+
if ($header === null || $header === '' || $header === '0') {
162162
return $strictMatch ? '' : $supported[0];
163163
}
164164

0 commit comments

Comments
 (0)