Skip to content

Commit c0194fb

Browse files
committed
fix: remove unneeded conditions
1 parent c6142f9 commit c0194fb

Some content is hidden

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

42 files changed

+139
-100
lines changed

Diff for: system/API/ResponseTrait.php

+1-1
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 = $status === null || $status === 0 ? 200 : $status;
97+
$status ??= 200;
9898
$output = $this->format($data);
9999
}
100100

Diff for: system/Autoloader/FileLocator.php

+16-14
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public function __construct(Autoloader $autoloader)
3535
* Attempts to locate a file by examining the name for a namespace
3636
* and looking through the PSR-4 namespaced files that we know about.
3737
*
38-
* @param string $file The relative file path or namespaced file to
39-
* locate. If not namespaced, search in the app
40-
* folder.
41-
* @param string|null $folder The folder within the namespace that we should
42-
* look for the file. If $file does not contain
43-
* this value, it will be appended to the namespace
44-
* folder.
45-
* @param string $ext The file extension the file should have.
38+
* @param string $file The relative file path or namespaced file to
39+
* locate. If not namespaced, search in the app
40+
* folder.
41+
* @param non-empty-string|null $folder The folder within the namespace that we should
42+
* look for the file. If $file does not contain
43+
* this value, it will be appended to the namespace
44+
* folder.
45+
* @param string $ext The file extension the file should have.
4646
*
4747
* @return false|string The path to the file, or false if not found.
4848
*/
@@ -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 ($folder !== null && $folder !== '' && $folder !== '0' && strpos($file, $folder) === 0) {
54+
if ($folder !== null && 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 ($folder !== null && $folder !== '' && $folder !== '0' && strpos($path . $filename, '/' . $folder . '/') === false) {
104+
if ($folder !== null && 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 ($className === '' || $className === '0') {
157+
if ($className === '') {
158158
return '';
159159
}
160160

@@ -305,7 +305,7 @@ public function findQualifiedNameFromPath(string $path)
305305
*/
306306
public function listFiles(string $path): array
307307
{
308-
if ($path === '' || $path === '0') {
308+
if ($path === '') {
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 ($path === '' || $path === '0' || ($prefix === '' || $prefix === '0')) {
341+
if ($path === '' || ($prefix === '')) {
342342
return [];
343343
}
344344

@@ -368,11 +368,13 @@ public function listNamespaceFiles(string $prefix, string $path): array
368368
* Checks the app folder to see if the file can be found.
369369
* Only for use with filenames that DO NOT include namespacing.
370370
*
371+
* @param non-empty-string|null $folder
372+
*
371373
* @return false|string The path to the file, or false if not found.
372374
*/
373375
protected function legacyLocate(string $file, ?string $folder = null)
374376
{
375-
$path = APPPATH . ($folder === null || $folder === '' || $folder === '0' ? $file : $folder . '/' . $file);
377+
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
376378
$path = realpath($path) ?: $path;
377379

378380
if (is_file($path)) {

Diff for: system/CLI/CLI.php

+1-1
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 ($string === null || $string === '' || $string === '0') {
852+
if ($string === null || $string === '') {
853853
return '';
854854
}
855855

Diff for: system/Cache/CacheFactory.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class CacheFactory
4040
/**
4141
* Attempts to create the desired cache handler, based upon the
4242
*
43+
* @param non-empty-string|null $handler
44+
* @param non-empty-string|null $backup
45+
*
4346
* @return CacheInterface
4447
*/
4548
public static function getHandler(Cache $config, ?string $handler = null, ?string $backup = null)
@@ -52,8 +55,8 @@ public static function getHandler(Cache $config, ?string $handler = null, ?strin
5255
throw CacheException::forNoBackup();
5356
}
5457

55-
$handler = $handler !== null && $handler !== '' && $handler !== '0' ? $handler : $config->handler;
56-
$backup = $backup !== null && $backup !== '' && $backup !== '0' ? $backup : $config->backupHandler;
58+
$handler ??= $config->handler;
59+
$backup ??= $config->backupHandler;
5760

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

Diff for: system/Common.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,24 @@ function csrf_hash(): string
288288
if (! function_exists('csrf_field')) {
289289
/**
290290
* Generates a hidden input field for use within manually generated forms.
291+
*
292+
* @param non-empty-string|null $id
291293
*/
292294
function csrf_field(?string $id = null): string
293295
{
294-
return '<input type="hidden"' . ($id !== null && $id !== '' && $id !== '0' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>';
296+
return '<input type="hidden"' . ($id !== null ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>';
295297
}
296298
}
297299

298300
if (! function_exists('csrf_meta')) {
299301
/**
300302
* Generates a meta tag for use within javascript calls.
303+
*
304+
* @param non-empty-string|null $id
301305
*/
302306
function csrf_meta(?string $id = null): string
303307
{
304-
return '<meta' . ($id !== null && $id !== '' && $id !== '0' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>';
308+
return '<meta' . ($id !== null ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>';
305309
}
306310
}
307311

@@ -850,13 +854,13 @@ function old(string $key, $default = null, $escape = 'html')
850854
*
851855
* If more control is needed, you must use $response->redirect explicitly.
852856
*
853-
* @param string|null $route Route name or Controller::method
857+
* @param non-empty-string|null $route Route name or Controller::method
854858
*/
855859
function redirect(?string $route = null): RedirectResponse
856860
{
857861
$response = Services::redirectresponse(null, true);
858862

859-
if ($route !== null && $route !== '' && $route !== '0') {
863+
if ($route !== null) {
860864
return $response->route($route);
861865
}
862866

@@ -1121,15 +1125,16 @@ function stringify_attributes($attributes, bool $js = false): string
11211125
* returns its return value if any.
11221126
* Otherwise will start or stop the timer intelligently.
11231127
*
1128+
* @param non-empty-string|null $name
11241129
* @param (callable(): mixed)|null $callable
11251130
*
1126-
* @return Timer
1131+
* @return mixed|Timer
11271132
*/
11281133
function timer(?string $name = null, ?callable $callable = null)
11291134
{
11301135
$timer = Services::timer();
11311136

1132-
if ($name === null || $name === '' || $name === '0') {
1137+
if ($name === null) {
11331138
return $timer;
11341139
}
11351140

Diff for: system/Database/BaseBuilder.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
920920
* @used-by whereNotIn()
921921
* @used-by orWhereNotIn()
922922
*
923+
* @param non-empty-string|null $key
923924
* @param array|BaseBuilder|Closure|null $values The values searched on, or anonymous function with subquery
924925
*
925926
* @return $this
@@ -928,7 +929,7 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
928929
*/
929930
protected function _whereIn(?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null, string $clause = 'QBWhere')
930931
{
931-
if ($key === null || $key === '' || $key === '0' || ! is_string($key)) {
932+
if ($key === null || $key === '') {
932933
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
933934
}
934935

@@ -1434,7 +1435,7 @@ public function orHaving($key, $value = null, ?bool $escape = null)
14341435
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
14351436
{
14361437
$qbOrderBy = [];
1437-
if ($orderBy === '' || $orderBy === '0') {
1438+
if ($orderBy === '') {
14381439
return $this;
14391440
}
14401441

@@ -1505,7 +1506,7 @@ public function limit(?int $value = null, ?int $offset = 0)
15051506
public function offset(int $offset)
15061507
{
15071508
if ($offset !== 0) {
1508-
$this->QBOffset = (int) $offset;
1509+
$this->QBOffset = $offset;
15091510
}
15101511

15111512
return $this;
@@ -3265,10 +3266,10 @@ protected function isLiteral(string $str): bool
32653266
{
32663267
$str = trim($str);
32673268

3268-
if ($str === '' || $str === '0'
3269-
|| ctype_digit($str)
3270-
|| (string) (float) $str === $str
3271-
|| in_array(strtoupper($str), ['TRUE', 'FALSE'], true)
3269+
if ($str === ''
3270+
|| ctype_digit($str)
3271+
|| (string) (float) $str === $str
3272+
|| in_array(strtoupper($str), ['TRUE', 'FALSE'], true)
32723273
) {
32733274
return true;
32743275
}

Diff for: system/Database/Database.php

+1-1
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 (isset($dsn['query']) && ($dsn['query'] !== '' && $dsn['query'] !== '0')) {
107+
if (isset($dsn['query']) && ($dsn['query'] !== '')) {
108108
parse_str($dsn['query'], $extra);
109109

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

Diff for: system/Database/MigrationRunner.php

+1-1
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 ($group !== '' && $group !== '0') {
642+
if ($group !== '') {
643643
$builder->where('group', $group);
644644
}
645645

Diff for: system/Database/SQLSRV/Connection.php

+1-1
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 ($databaseName === null || $databaseName === '' || $databaseName === '0') {
447+
if ($databaseName === null || $databaseName === '') {
448448
$databaseName = $this->database;
449449
}
450450

Diff for: system/Database/Seeder.php

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

Diff for: system/Debug/BaseExceptionHandler.php

+1-1
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 ($file === '' || $file === '0' || ! is_readable($file)) {
164+
if ($file === '' || ! is_readable($file)) {
165165
return false;
166166
}
167167

Diff for: system/Debug/Exceptions.php

+1-1
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 ($file === '' || $file === '0' || ! is_readable($file)) {
525+
if ($file === '' || ! is_readable($file)) {
526526
return false;
527527
}
528528

Diff for: system/Debug/Timer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function has(string $name): bool
136136
* @param string $name The name of the timer
137137
* @param callable(): mixed $callable callable to be executed
138138
*
139-
* @return array|bool|float|int|object|resource|string|null
139+
* @return mixed
140140
*/
141141
public function record(string $name, callable $callable)
142142
{

Diff for: system/HTTP/CLIRequest.php

+1-1
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 $path === '' || $path === '0' ? '' : $path;
98+
return ($path === '') ? '' : $path;
9999
}
100100

101101
/**

Diff for: system/HTTP/ContentSecurityPolicy.php

+1-1
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) && ($reportOnly !== '' && $reportOnly !== '0')) {
793+
if (is_numeric($value) && is_string($reportOnly) && ($reportOnly !== '')) {
794794
$value = $reportOnly;
795795
$reportOnly = $this->reportOnly;
796796
}

Diff for: system/HTTP/IncomingRequest.php

+1-1
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 ($protocol === '' || $protocol === '0') {
259+
if ($protocol === '') {
260260
$protocol = 'REQUEST_URI';
261261
}
262262

Diff for: system/HTTP/Negotiate.php

+2-2
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 ($match === '' || $match === '0') {
96+
if ($match === '') {
9797
return 'utf-8';
9898
}
9999

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

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

Diff for: system/HTTP/ResponseTrait.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ public function setStatusCode(int $code, string $reason = '')
156156
}
157157

158158
// Unknown and no message?
159-
if (! array_key_exists($code, static::$statusCodes) && ($reason === '' || $reason === '0')) {
159+
if (! array_key_exists($code, static::$statusCodes) && ($reason === '')) {
160160
throw HTTPException::forUnkownStatusCode($code);
161161
}
162162

163163
$this->statusCode = $code;
164164

165-
$this->reason = $reason !== '' && $reason !== '0' ? $reason : static::$statusCodes[$code];
165+
$this->reason = ($reason !== '') ? $reason : static::$statusCodes[$code];
166166

167167
return $this;
168168
}
@@ -226,7 +226,7 @@ public function setLink(PagerInterface $pager)
226226
public function setContentType(string $mime, string $charset = 'UTF-8')
227227
{
228228
// add charset attribute if not already there and provided as parm
229-
if ((strpos($mime, 'charset=') < 1) && ($charset !== '' && $charset !== '0')) {
229+
if ((strpos($mime, 'charset=') < 1) && ($charset !== '')) {
230230
$mime .= '; charset=' . $charset;
231231
}
232232

0 commit comments

Comments
 (0)