diff --git a/phpstan-baseline.php b/phpstan-baseline.php
index 7acea4e7e82e..d4877780cf88 100644
--- a/phpstan-baseline.php
+++ b/phpstan-baseline.php
@@ -18,7 +18,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 10,
+ 'count' => 3,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
@@ -33,7 +33,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 10,
+ 'count' => 8,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
@@ -81,11 +81,6 @@
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/CLI/CLI.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#',
'count' => 1,
@@ -136,11 +131,6 @@
'count' => 5,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
- 'path' => __DIR__ . '/system/Cache/CacheFactory.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in &&, string given on the left side\\.$#',
'count' => 1,
@@ -763,7 +753,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 8,
+ 'count' => 4,
'path' => __DIR__ . '/system/Common.php',
];
$ignoreErrors[] = [
@@ -871,14 +861,9 @@
'count' => 5,
'path' => __DIR__ . '/system/Cookie/Cookie.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Call to function is_string\\(\\) with non\\-falsy\\-string will always evaluate to true\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/Database/BaseBuilder.php',
-];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 40,
+ 'count' => 30,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
@@ -1068,7 +1053,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
+ 'count' => 2,
'path' => __DIR__ . '/system/Database/Database.php',
];
$ignoreErrors[] = [
@@ -1143,7 +1128,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 6,
+ 'count' => 5,
'path' => __DIR__ . '/system/Database/MigrationRunner.php',
];
$ignoreErrors[] = [
@@ -1203,7 +1188,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 12,
+ 'count' => 11,
'path' => __DIR__ . '/system/Database/MySQLi/Connection.php',
];
$ignoreErrors[] = [
@@ -1268,7 +1253,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 4,
+ 'count' => 3,
'path' => __DIR__ . '/system/Database/OCI8/Builder.php',
];
$ignoreErrors[] = [
@@ -1368,7 +1353,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 8,
+ 'count' => 7,
'path' => __DIR__ . '/system/Database/Postgre/Builder.php',
];
$ignoreErrors[] = [
@@ -1533,7 +1518,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 10,
+ 'count' => 9,
'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php',
];
$ignoreErrors[] = [
@@ -1558,7 +1543,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 8,
+ 'count' => 6,
'path' => __DIR__ . '/system/Database/SQLSRV/Connection.php',
];
$ignoreErrors[] = [
@@ -1721,11 +1706,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/SQLite3/Utils.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/Database/Seeder.php',
-];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Database\\\\Seeder\\:\\:call\\(\\) has no return type specified\\.$#',
'count' => 1,
@@ -1738,17 +1718,17 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/Debug/BaseExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/Debug/ExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
+ 'count' => 1,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
@@ -1798,7 +1778,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 14,
+ 'count' => 12,
'path' => __DIR__ . '/system/Email/Email.php',
];
$ignoreErrors[] = [
@@ -1931,11 +1911,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Filters/Filters.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/HTTP/CLIRequest.php',
-];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 10,
@@ -1953,7 +1928,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 7,
+ 'count' => 6,
'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php',
];
$ignoreErrors[] = [
@@ -2068,7 +2043,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 5,
+ 'count' => 2,
'path' => __DIR__ . '/system/HTTP/IncomingRequest.php',
];
$ignoreErrors[] = [
@@ -2101,11 +2076,6 @@
'count' => 1,
'path' => __DIR__ . '/system/HTTP/Negotiate.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
- 'path' => __DIR__ . '/system/HTTP/Negotiate.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\|null given\\.$#',
'count' => 1,
@@ -2158,7 +2128,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 5,
+ 'count' => 2,
'path' => __DIR__ . '/system/HTTP/Response.php',
];
$ignoreErrors[] = [
@@ -2193,7 +2163,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 15,
+ 'count' => 10,
'path' => __DIR__ . '/system/HTTP/URI.php',
];
$ignoreErrors[] = [
@@ -2228,7 +2198,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
+ 'count' => 2,
'path' => __DIR__ . '/system/HTTP/UserAgent.php',
];
$ignoreErrors[] = [
@@ -2236,11 +2206,6 @@
'count' => 4,
'path' => __DIR__ . '/system/HTTP/UserAgent.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/Helpers/date_helper.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 1024\\> given\\.$#',
'count' => 2,
@@ -2341,21 +2306,11 @@
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 5,
- 'path' => __DIR__ . '/system/Helpers/html_helper.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/html_helper.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
- 'path' => __DIR__ . '/system/Helpers/number_helper.php',
-];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 2,
@@ -2393,7 +2348,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/Honeypot/Honeypot.php',
];
$ignoreErrors[] = [
@@ -2401,11 +2356,6 @@
'count' => 1,
'path' => __DIR__ . '/system/HotReloader/HotReloader.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
- 'path' => __DIR__ . '/system/I18n/Time.php',
-];
$ignoreErrors[] = [
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimestamp\\(\\)$#',
'count' => 1,
@@ -2421,11 +2371,6 @@
'count' => 4,
'path' => __DIR__ . '/system/I18n/Time.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
- 'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
-];
$ignoreErrors[] = [
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimestamp\\(\\)$#',
'count' => 1,
@@ -2473,7 +2418,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 10,
+ 'count' => 9,
'path' => __DIR__ . '/system/Images/Handlers/ImageMagickHandler.php',
];
$ignoreErrors[] = [
@@ -2523,7 +2468,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 16,
+ 'count' => 15,
'path' => __DIR__ . '/system/Model.php',
];
$ignoreErrors[] = [
@@ -2563,7 +2508,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 4,
+ 'count' => 1,
'path' => __DIR__ . '/system/Pager/Pager.php',
];
$ignoreErrors[] = [
@@ -2603,14 +2548,9 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/RESTful/ResourceController.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 3,
- 'path' => __DIR__ . '/system/Router/AutoRouter.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#',
'count' => 1,
@@ -2638,7 +2578,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 8,
+ 'count' => 6,
'path' => __DIR__ . '/system/Router/RouteCollection.php',
];
$ignoreErrors[] = [
@@ -2798,7 +2738,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 4,
+ 'count' => 3,
'path' => __DIR__ . '/system/Router/Router.php',
];
$ignoreErrors[] = [
@@ -2923,7 +2863,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/Session/Handlers/MemcachedHandler.php',
];
$ignoreErrors[] = [
@@ -2933,7 +2873,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 5,
+ 'count' => 4,
'path' => __DIR__ . '/system/Session/Handlers/RedisHandler.php',
];
$ignoreErrors[] = [
@@ -2948,7 +2888,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 12,
+ 'count' => 9,
'path' => __DIR__ . '/system/Session/Session.php',
];
$ignoreErrors[] = [
@@ -3278,7 +3218,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 10,
+ 'count' => 5,
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
];
$ignoreErrors[] = [
@@ -3563,7 +3503,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 2,
+ 'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockResourcePresenter.php',
];
$ignoreErrors[] = [
@@ -3816,11 +3756,6 @@
'count' => 6,
'path' => __DIR__ . '/system/Validation/FileRules.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 4,
- 'path' => __DIR__ . '/system/Validation/FormatRules.php',
-];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 8,
@@ -3833,7 +3768,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 5,
+ 'count' => 3,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
@@ -3863,7 +3798,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
- 'count' => 6,
+ 'count' => 4,
'path' => __DIR__ . '/system/View/Parser.php',
];
$ignoreErrors[] = [
diff --git a/rector.php b/rector.php
index 65f5b8fcbec9..6d69a0fba2fd 100644
--- a/rector.php
+++ b/rector.php
@@ -23,6 +23,7 @@
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
+use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector;
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector;
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
@@ -43,7 +44,9 @@
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
+use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
+use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
@@ -139,6 +142,9 @@
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
$rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
+ $rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class);
+ $rectorConfig->rule(EmptyOnNullableObjectToInstanceOfRector::class);
+ $rectorConfig->rule(DisallowedEmptyRuleFixerRector::class);
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
diff --git a/system/API/ResponseTrait.php b/system/API/ResponseTrait.php
index 5a350007f3fa..d5b198ae93fb 100644
--- a/system/API/ResponseTrait.php
+++ b/system/API/ResponseTrait.php
@@ -94,7 +94,7 @@ protected function respond($data = null, ?int $status = null, string $message =
$output = null;
$this->format($data);
} else {
- $status = empty($status) ? 200 : $status;
+ $status ??= 200;
$output = $this->format($data);
}
diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php
index e9ce492c54d6..11aa56edc4f7 100644
--- a/system/Autoloader/FileLocator.php
+++ b/system/Autoloader/FileLocator.php
@@ -35,14 +35,14 @@ public function __construct(Autoloader $autoloader)
* Attempts to locate a file by examining the name for a namespace
* and looking through the PSR-4 namespaced files that we know about.
*
- * @param string $file The relative file path or namespaced file to
- * locate. If not namespaced, search in the app
- * folder.
- * @param string|null $folder The folder within the namespace that we should
- * look for the file. If $file does not contain
- * this value, it will be appended to the namespace
- * folder.
- * @param string $ext The file extension the file should have.
+ * @param string $file The relative file path or namespaced file to
+ * locate. If not namespaced, search in the app
+ * folder.
+ * @param non-empty-string|null $folder The folder within the namespace that we should
+ * look for the file. If $file does not contain
+ * this value, it will be appended to the namespace
+ * folder.
+ * @param string $ext The file extension the file should have.
*
* @return false|string The path to the file, or false if not found.
*/
@@ -51,7 +51,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
$file = $this->ensureExt($file, $ext);
// Clears the folder name if it is at the beginning of the filename
- if (! empty($folder) && strpos($file, $folder) === 0) {
+ if ($folder !== null && strpos($file, $folder) === 0) {
$file = substr($file, strlen($folder . '/'));
}
@@ -101,7 +101,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
// If we have a folder name, then the calling function
// expects this file to be within that folder, like 'Views',
// or 'libraries'.
- if (! empty($folder) && strpos($path . $filename, '/' . $folder . '/') === false) {
+ if ($folder !== null && strpos($path . $filename, '/' . $folder . '/') === false) {
$path .= trim($folder, '/') . '/';
}
@@ -154,7 +154,7 @@ public function getClassname(string $file): string
}
}
- if (empty($className)) {
+ if ($className === '') {
return '';
}
@@ -305,7 +305,7 @@ public function findQualifiedNameFromPath(string $path)
*/
public function listFiles(string $path): array
{
- if (empty($path)) {
+ if ($path === '') {
return [];
}
@@ -338,7 +338,7 @@ public function listFiles(string $path): array
*/
public function listNamespaceFiles(string $prefix, string $path): array
{
- if (empty($path) || empty($prefix)) {
+ if ($path === '' || ($prefix === '')) {
return [];
}
@@ -368,11 +368,13 @@ public function listNamespaceFiles(string $prefix, string $path): array
* Checks the app folder to see if the file can be found.
* Only for use with filenames that DO NOT include namespacing.
*
+ * @param non-empty-string|null $folder
+ *
* @return false|string The path to the file, or false if not found.
*/
protected function legacyLocate(string $file, ?string $folder = null)
{
- $path = APPPATH . (empty($folder) ? $file : $folder . '/' . $file);
+ $path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
$path = realpath($path) ?: $path;
if (is_file($path)) {
diff --git a/system/BaseModel.php b/system/BaseModel.php
index fcda6b134498..1b669a30d2c2 100644
--- a/system/BaseModel.php
+++ b/system/BaseModel.php
@@ -1579,7 +1579,7 @@ public function getValidationMessages(): array
*/
protected function cleanValidationRules(array $rules, ?array $row = null): array
{
- if (empty($row)) {
+ if ($row === null || $row === []) {
return [];
}
@@ -1795,7 +1795,7 @@ protected function transformDataToArray($row, string $type): array
}
// If it's still empty here, means $row is no change or is empty object
- if (! $this->allowEmptyInserts && empty($row)) {
+ if (! $this->allowEmptyInserts && ($row === null || $row === [])) {
throw DataException::forEmptyDataset($type);
}
diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php
index 64b576735486..9a50e4038184 100644
--- a/system/CLI/CLI.php
+++ b/system/CLI/CLI.php
@@ -849,7 +849,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
*/
public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string
{
- if (empty($string)) {
+ if ($string === null || $string === '') {
return '';
}
diff --git a/system/Cache/CacheFactory.php b/system/Cache/CacheFactory.php
index 95e07ef813c8..6402b002866d 100644
--- a/system/Cache/CacheFactory.php
+++ b/system/Cache/CacheFactory.php
@@ -40,6 +40,9 @@ class CacheFactory
/**
* Attempts to create the desired cache handler, based upon the
*
+ * @param non-empty-string|null $handler
+ * @param non-empty-string|null $backup
+ *
* @return CacheInterface
*/
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
throw CacheException::forNoBackup();
}
- $handler = ! empty($handler) ? $handler : $config->handler;
- $backup = ! empty($backup) ? $backup : $config->backupHandler;
+ $handler ??= $config->handler;
+ $backup ??= $config->backupHandler;
if (! array_key_exists($handler, $config->validHandlers) || ! array_key_exists($backup, $config->validHandlers)) {
throw CacheException::forHandlerNotFound();
diff --git a/system/Common.php b/system/Common.php
index 56e1c07b6e3e..690fa3fc5b6a 100644
--- a/system/Common.php
+++ b/system/Common.php
@@ -288,20 +288,24 @@ function csrf_hash(): string
if (! function_exists('csrf_field')) {
/**
* Generates a hidden input field for use within manually generated forms.
+ *
+ * @param non-empty-string|null $id
*/
function csrf_field(?string $id = null): string
{
- return '';
+ return '';
}
}
if (! function_exists('csrf_meta')) {
/**
* Generates a meta tag for use within javascript calls.
+ *
+ * @param non-empty-string|null $id
*/
function csrf_meta(?string $id = null): string
{
- return '';
+ return '';
}
}
@@ -850,13 +854,13 @@ function old(string $key, $default = null, $escape = 'html')
*
* If more control is needed, you must use $response->redirect explicitly.
*
- * @param string|null $route Route name or Controller::method
+ * @param non-empty-string|null $route Route name or Controller::method
*/
function redirect(?string $route = null): RedirectResponse
{
$response = Services::redirectresponse(null, true);
- if (! empty($route)) {
+ if ($route !== null) {
return $response->route($route);
}
@@ -1121,15 +1125,17 @@ function stringify_attributes($attributes, bool $js = false): string
* returns its return value if any.
* Otherwise will start or stop the timer intelligently.
*
+ * @param non-empty-string|null $name
* @param (callable(): mixed)|null $callable
*
- * @return Timer
+ * @return mixed|Timer
+ * @phpstan-return ($name is null ? Timer : ($callable is (callable(): mixed) ? mixed : Timer))
*/
function timer(?string $name = null, ?callable $callable = null)
{
$timer = Services::timer();
- if (empty($name)) {
+ if ($name === null) {
return $timer;
}
diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php
index 6e3829fa079b..9d43e5577943 100644
--- a/system/Database/BaseBuilder.php
+++ b/system/Database/BaseBuilder.php
@@ -318,7 +318,7 @@ public function __construct($tableName, ConnectionInterface $db, ?array $options
$this->from($tableName);
- if (! empty($options)) {
+ if ($options !== null && $options !== []) {
foreach ($options as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
@@ -920,6 +920,7 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
* @used-by whereNotIn()
* @used-by orWhereNotIn()
*
+ * @param non-empty-string|null $key
* @param array|BaseBuilder|Closure|null $values The values searched on, or anonymous function with subquery
*
* @return $this
@@ -928,7 +929,7 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
*/
protected function _whereIn(?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null, string $clause = 'QBWhere')
{
- if (empty($key) || ! is_string($key)) {
+ if ($key === null || $key === '') {
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
}
@@ -1434,7 +1435,7 @@ public function orHaving($key, $value = null, ?bool $escape = null)
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
{
$qbOrderBy = [];
- if (empty($orderBy)) {
+ if ($orderBy === '') {
return $this;
}
@@ -1490,7 +1491,7 @@ public function limit(?int $value = null, ?int $offset = 0)
$this->QBLimit = $value;
}
- if (! empty($offset)) {
+ if ($offset !== null && $offset !== 0) {
$this->QBOffset = $offset;
}
@@ -1504,8 +1505,8 @@ public function limit(?int $value = null, ?int $offset = 0)
*/
public function offset(int $offset)
{
- if (! empty($offset)) {
- $this->QBOffset = (int) $offset;
+ if ($offset !== 0) {
+ $this->QBOffset = $offset;
}
return $this;
@@ -1736,7 +1737,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
$this->where($where);
}
- if (! empty($limit)) {
+ if ($limit !== null && $limit !== 0) {
$this->limit($limit, $offset);
}
@@ -2452,7 +2453,7 @@ public function update($set = null, $where = null, ?int $limit = null): bool
$this->where($where);
}
- if (! empty($limit)) {
+ if ($limit !== null && $limit !== 0) {
if (! $this->canLimitWhereUpdates) {
throw new DatabaseException('This driver does not allow LIMITs on UPDATE queries using WHERE.');
}
@@ -2762,7 +2763,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
$sql = $this->_delete($this->removeAlias($table));
- if (! empty($limit)) {
+ if ($limit !== null && $limit !== 0) {
$this->QBLimit = $limit;
}
@@ -3172,7 +3173,7 @@ protected function compileGroupBy(): string
*/
protected function compileOrderBy(): string
{
- if (is_array($this->QBOrderBy) && ! empty($this->QBOrderBy)) {
+ if (is_array($this->QBOrderBy) && $this->QBOrderBy !== []) {
foreach ($this->QBOrderBy as &$orderBy) {
if ($orderBy['escape'] !== false && ! $this->isLiteral($orderBy['field'])) {
$orderBy['field'] = $this->db->protectIdentifiers($orderBy['field']);
@@ -3265,7 +3266,7 @@ protected function isLiteral(string $str): bool
{
$str = trim($str);
- if (empty($str)
+ if ($str === ''
|| ctype_digit($str)
|| (string) (float) $str === $str
|| in_array(strtoupper($str), ['TRUE', 'FALSE'], true)
diff --git a/system/Database/Database.php b/system/Database/Database.php
index 2818fe220928..58a63e152fba 100644
--- a/system/Database/Database.php
+++ b/system/Database/Database.php
@@ -104,7 +104,7 @@ protected function parseDSN(array $params): array
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : '',
];
- if (! empty($dsn['query'])) {
+ if (isset($dsn['query']) && ($dsn['query'] !== '')) {
parse_str($dsn['query'], $extra);
foreach ($extra as $key => $val) {
diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php
index af8f191c276c..435c11852ae0 100644
--- a/system/Database/MigrationRunner.php
+++ b/system/Database/MigrationRunner.php
@@ -639,7 +639,7 @@ public function getHistory(string $group = 'default'): array
$builder = $this->db->table($this->table);
// If group was specified then use it
- if (! empty($group)) {
+ if ($group !== '') {
$builder->where('group', $group);
}
diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php
index 45b306ce2a44..3139185f1bc4 100644
--- a/system/Database/MySQLi/Connection.php
+++ b/system/Database/MySQLi/Connection.php
@@ -150,7 +150,7 @@ public function connect(bool $persistent = false)
$ssl['cipher'] = $this->encrypt['ssl_cipher'];
}
- if (! empty($ssl)) {
+ if ($ssl !== []) {
if (isset($this->encrypt['ssl_verify'])) {
if ($this->encrypt['ssl_verify']) {
if (defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT')) {
diff --git a/system/Database/OCI8/Builder.php b/system/Database/OCI8/Builder.php
index bccb0bc54716..f5527ce745c6 100644
--- a/system/Database/OCI8/Builder.php
+++ b/system/Database/OCI8/Builder.php
@@ -166,7 +166,7 @@ protected function _truncate(string $table): string
*/
public function delete($where = '', ?int $limit = null, bool $resetData = true)
{
- if (! empty($limit)) {
+ if ($limit !== null && $limit !== 0) {
$this->QBLimit = $limit;
}
diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php
index e9763089a90f..3e3ed68a9356 100644
--- a/system/Database/Postgre/Builder.php
+++ b/system/Database/Postgre/Builder.php
@@ -229,7 +229,7 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
*/
public function delete($where = '', ?int $limit = null, bool $resetData = true)
{
- if (! empty($limit) || ! empty($this->QBLimit)) {
+ if ($limit !== null && $limit !== 0 || ! empty($this->QBLimit)) {
throw new DatabaseException('PostgreSQL does not allow LIMITs on DELETE queries.');
}
diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php
index b4e77f1d2cf8..c86e82633091 100755
--- a/system/Database/SQLSRV/Builder.php
+++ b/system/Database/SQLSRV/Builder.php
@@ -522,7 +522,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
return false; // @codeCoverageIgnore
}
- if (! empty($limit)) {
+ if ($limit !== null && $limit !== 0) {
$this->QBLimit = $limit;
}
diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php
index f1a9fb0b433a..bd9a22e94975 100755
--- a/system/Database/SQLSRV/Connection.php
+++ b/system/Database/SQLSRV/Connection.php
@@ -444,7 +444,7 @@ public function affectedRows(): int
*/
public function setDatabase(?string $databaseName = null)
{
- if (empty($databaseName)) {
+ if ($databaseName === null || $databaseName === '') {
$databaseName = $this->database;
}
@@ -538,7 +538,7 @@ public function getVersion(): string
return $this->dataCache['version'];
}
- if (! $this->connID || empty($info = sqlsrv_server_info($this->connID))) {
+ if (! $this->connID || ($info = sqlsrv_server_info($this->connID)) === []) {
$this->initialize();
}
diff --git a/system/Database/Seeder.php b/system/Database/Seeder.php
index 749f6f34d5c7..c0f267d2fee0 100644
--- a/system/Database/Seeder.php
+++ b/system/Database/Seeder.php
@@ -78,7 +78,7 @@ public function __construct(Database $config, ?BaseConnection $db = null)
{
$this->seedPath = $config->filesPath ?? APPPATH . 'Database/';
- if (empty($this->seedPath)) {
+ if ($this->seedPath === '') {
throw new InvalidArgumentException('Invalid filesPath set in the Config\Database.');
}
diff --git a/system/Debug/BaseExceptionHandler.php b/system/Debug/BaseExceptionHandler.php
index d4f045797366..33dd126ff1ec 100644
--- a/system/Debug/BaseExceptionHandler.php
+++ b/system/Debug/BaseExceptionHandler.php
@@ -161,7 +161,7 @@ protected static function describeMemory(int $bytes): string
*/
protected static function highlightFile(string $file, int $lineNumber, int $lines = 15)
{
- if (empty($file) || ! is_readable($file)) {
+ if ($file === '' || ! is_readable($file)) {
return false;
}
diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php
index 145474c6c633..1f5a5b52f03b 100644
--- a/system/Debug/Exceptions.php
+++ b/system/Debug/Exceptions.php
@@ -522,7 +522,7 @@ public static function describeMemory(int $bytes): string
*/
public static function highlightFile(string $file, int $lineNumber, int $lines = 15)
{
- if (empty($file) || ! is_readable($file)) {
+ if ($file === '' || ! is_readable($file)) {
return false;
}
diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php
index 103094b0a641..45c0bf865c8e 100644
--- a/system/Debug/Timer.php
+++ b/system/Debug/Timer.php
@@ -136,7 +136,7 @@ public function has(string $name): bool
* @param string $name The name of the timer
* @param callable(): mixed $callable callable to be executed
*
- * @return array|bool|float|int|object|resource|string|null
+ * @return mixed
*/
public function record(string $name, callable $callable)
{
diff --git a/system/Email/Email.php b/system/Email/Email.php
index 6a7510b1d2a9..d18b40ff7cef 100644
--- a/system/Email/Email.php
+++ b/system/Email/Email.php
@@ -1236,13 +1236,13 @@ protected function buildMessage()
. $this->prepQuotedPrintable($this->body) . $this->newline . $this->newline
. '--' . $altBoundary . '--' . $this->newline . $this->newline;
- if (! empty($relBoundary)) {
+ if (isset($relBoundary)) {
$body .= $this->newline . $this->newline;
$this->appendAttachments($body, $relBoundary, 'related');
}
// multipart/mixed attachments
- if (! empty($atcBoundary)) {
+ if (isset($atcBoundary)) {
$body .= $this->newline . $this->newline;
$this->appendAttachments($body, $atcBoundary, 'mixed');
}
diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php
index 1d15619c8016..01823dbfc4c5 100644
--- a/system/HTTP/CLIRequest.php
+++ b/system/HTTP/CLIRequest.php
@@ -95,7 +95,7 @@ public function getPath(): string
{
$path = implode('/', $this->segments);
- return empty($path) ? '' : $path;
+ return ($path === '') ? '' : $path;
}
/**
diff --git a/system/HTTP/ContentSecurityPolicy.php b/system/HTTP/ContentSecurityPolicy.php
index 660d26b6ab88..f4970bf7c544 100644
--- a/system/HTTP/ContentSecurityPolicy.php
+++ b/system/HTTP/ContentSecurityPolicy.php
@@ -790,7 +790,7 @@ protected function addToHeader(string $name, $values = null)
$reportSources = [];
foreach ($values as $value => $reportOnly) {
- if (is_numeric($value) && is_string($reportOnly) && ! empty($reportOnly)) {
+ if (is_numeric($value) && is_string($reportOnly) && ($reportOnly !== '')) {
$value = $reportOnly;
$reportOnly = $this->reportOnly;
}
diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php
index 48b9f3f61be4..8bc246f7956d 100755
--- a/system/HTTP/IncomingRequest.php
+++ b/system/HTTP/IncomingRequest.php
@@ -152,7 +152,7 @@ class IncomingRequest extends Request
*/
public function __construct($config, ?URI $uri = null, $body = 'php://input', ?UserAgent $userAgent = null)
{
- if (empty($uri) || empty($userAgent)) {
+ if (! $uri instanceof URI || ! $userAgent instanceof UserAgent) {
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.');
}
@@ -256,7 +256,7 @@ protected function detectURI(string $protocol, string $baseURL)
*/
public function detectPath(string $protocol = ''): string
{
- if (empty($protocol)) {
+ if ($protocol === '') {
$protocol = 'REQUEST_URI';
}
diff --git a/system/HTTP/Negotiate.php b/system/HTTP/Negotiate.php
index a9297669146a..9c903908695f 100644
--- a/system/HTTP/Negotiate.php
+++ b/system/HTTP/Negotiate.php
@@ -93,7 +93,7 @@ public function charset(array $supported): string
// If no charset is shown as a match, ignore the directive
// as allowed by the RFC, and tell it a default value.
- if (empty($match)) {
+ if ($match === '') {
return 'utf-8';
}
@@ -158,7 +158,7 @@ protected function getBestMatch(
throw HTTPException::forEmptySupportedNegotiations();
}
- if (empty($header)) {
+ if ($header === null || $header === '') {
return $strictMatch ? '' : $supported[0];
}
diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php
index 90637fdbd7cf..b385bfea45de 100644
--- a/system/HTTP/ResponseTrait.php
+++ b/system/HTTP/ResponseTrait.php
@@ -156,13 +156,13 @@ public function setStatusCode(int $code, string $reason = '')
}
// Unknown and no message?
- if (! array_key_exists($code, static::$statusCodes) && empty($reason)) {
+ if (! array_key_exists($code, static::$statusCodes) && ($reason === '')) {
throw HTTPException::forUnkownStatusCode($code);
}
$this->statusCode = $code;
- $this->reason = ! empty($reason) ? $reason : static::$statusCodes[$code];
+ $this->reason = ($reason !== '') ? $reason : static::$statusCodes[$code];
return $this;
}
@@ -226,7 +226,7 @@ public function setLink(PagerInterface $pager)
public function setContentType(string $mime, string $charset = 'UTF-8')
{
// add charset attribute if not already there and provided as parm
- if ((strpos($mime, 'charset=') < 1) && ! empty($charset)) {
+ if ((strpos($mime, 'charset=') < 1) && ($charset !== '')) {
$mime .= '; charset=' . $charset;
}
diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php
index 608f8b75d5ba..5bec38013bf2 100644
--- a/system/HTTP/URI.php
+++ b/system/HTTP/URI.php
@@ -163,11 +163,11 @@ public static function createURIString(
?string $fragment = null
): string {
$uri = '';
- if (! empty($scheme)) {
+ if ($scheme !== null && $scheme !== '') {
$uri .= $scheme . '://';
}
- if (! empty($authority)) {
+ if ($authority !== null && $authority !== '') {
$uri .= $authority;
}
@@ -886,7 +886,7 @@ public function setQuery(string $query)
}
// Can't have leading ?
- if (! empty($query) && strpos($query, '?') === 0) {
+ if ($query !== '' && strpos($query, '?') === 0) {
$query = substr($query, 1);
}
@@ -1097,7 +1097,7 @@ public function resolveRelativeURI(string $uri)
$transformed = clone $relative;
// 5.2.2 Transform References in a non-strict method (no scheme)
- if (! empty($relative->getAuthority())) {
+ if ($relative->getAuthority() !== '') {
$transformed
->setAuthority($relative->getAuthority())
->setPath($relative->getPath())
@@ -1139,7 +1139,7 @@ public function resolveRelativeURI(string $uri)
*/
protected function mergePaths(self $base, self $reference): string
{
- if (! empty($base->getAuthority()) && $base->getPath() === '') {
+ if ($base->getAuthority() !== '' && $base->getPath() === '') {
return '/' . ltrim($reference->getPath(), '/ ');
}
diff --git a/system/HTTP/UserAgent.php b/system/HTTP/UserAgent.php
index 77e7cb4392fc..2294b02a2b48 100644
--- a/system/HTTP/UserAgent.php
+++ b/system/HTTP/UserAgent.php
@@ -260,7 +260,7 @@ public function parse(string $string)
// Set the new user-agent string and parse it, unless empty
$this->agent = $string;
- if (! empty($string)) {
+ if ($string !== '') {
$this->compileData();
}
}
diff --git a/system/Helpers/date_helper.php b/system/Helpers/date_helper.php
index ba9c9a249455..cf1dc33a74ea 100644
--- a/system/Helpers/date_helper.php
+++ b/system/Helpers/date_helper.php
@@ -20,11 +20,13 @@
* Returns Time::now()->getTimestamp() based on the timezone parameter or on the
* app_timezone() setting
*
+ * @param non-empty-string|null $timezone
+ *
* @throws Exception
*/
function now(?string $timezone = null): int
{
- $timezone = empty($timezone) ? app_timezone() : $timezone;
+ $timezone = ($timezone === null || $timezone === '') ? app_timezone() : $timezone;
if ($timezone === 'local' || $timezone === date_default_timezone_get()) {
return Time::now()->getTimestamp();
diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php
index 88fb339832d1..075dcd510b43 100755
--- a/system/Helpers/html_helper.php
+++ b/system/Helpers/html_helper.php
@@ -313,7 +313,7 @@ function video($src, string $unsupportedMessage = '', string $attributes = '', a
$video .= _space_indent() . $track . "\n";
}
- if (! empty($unsupportedMessage)) {
+ if ($unsupportedMessage !== '') {
$video .= _space_indent()
. $unsupportedMessage
. "\n";
@@ -359,7 +359,7 @@ function audio($src, string $unsupportedMessage = '', string $attributes = '', a
$audio .= "\n" . _space_indent() . $track;
}
- if (! empty($unsupportedMessage)) {
+ if ($unsupportedMessage !== '') {
$audio .= "\n" . _space_indent() . $unsupportedMessage . "\n";
}
@@ -377,7 +377,7 @@ function _media(string $name, array $types = [], string $unsupportedMessage = ''
{
$media = '<' . $name;
- if (empty($attributes)) {
+ if ($attributes === '') {
$media .= '>';
} else {
$media .= ' ' . $attributes . '>';
@@ -393,7 +393,7 @@ function _media(string $name, array $types = [], string $unsupportedMessage = ''
$media .= _space_indent() . $track . "\n";
}
- if (! empty($unsupportedMessage)) {
+ if ($unsupportedMessage !== '') {
$media .= _space_indent() . $unsupportedMessage . "\n";
}
@@ -421,7 +421,7 @@ function source(string $src, string $type = 'unknown', string $attributes = '',
$source = '