From 70387ecb6faca8953e8f13700277ed86cf26bd8f Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 13 Aug 2026 18:52:45 +0800 Subject: [PATCH] refactor: fix `nullCoalesce.property` errors --- system/Files/File.php | 4 +- system/HTTP/Files/UploadedFile.php | 2 +- system/HTTP/Message.php | 2 +- system/HTTP/URI.php | 2 +- system/Test/FilterTestTrait.php | 8 ++-- system/Throttle/Throttler.php | 2 +- utils/phpstan-baseline/loader.neon | 3 +- .../nullCoalesce.property.neon | 38 ------------------- 8 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 utils/phpstan-baseline/nullCoalesce.property.neon diff --git a/system/Files/File.php b/system/Files/File.php index 181a9976362e..38eae2ebb6de 100644 --- a/system/Files/File.php +++ b/system/Files/File.php @@ -30,7 +30,7 @@ class File extends SplFileInfo /** * The files size in bytes * - * @var int + * @var false|int|null */ protected $size; @@ -65,7 +65,7 @@ public function __construct(string $path, bool $checkFile = false) */ public function getSize(): false|int { - return $this->size ?? ($this->size = parent::getSize()); + return $this->size ??= parent::getSize(); } /** diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index be2b74c2025c..cf7fa414701a 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -66,7 +66,7 @@ class UploadedFile extends File implements UploadedFileInterface * The error constant of the upload * (one of PHP's UPLOADERRXXX constants) * - * @var int + * @var int|null */ protected $error; diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index 5a490e09f780..4a3c70e123cc 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -27,7 +27,7 @@ class Message implements MessageInterface /** * Protocol version * - * @var string + * @var string|null */ protected $protocolVersion; diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index bc848ba5c73e..4f97e1fa75a4 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -541,7 +541,7 @@ public function getQuery(array $options = []): string */ public function getFragment(): string { - return $this->fragment ?? ''; + return $this->fragment; } /** diff --git a/system/Test/FilterTestTrait.php b/system/Test/FilterTestTrait.php index 59ffff646a79..ac97db432133 100644 --- a/system/Test/FilterTestTrait.php +++ b/system/Test/FilterTestTrait.php @@ -44,14 +44,14 @@ trait FilterTestTrait /** * The active IncomingRequest or CLIRequest * - * @var RequestInterface + * @var RequestInterface|null */ protected $request; /** * The active Response instance * - * @var ResponseInterface + * @var ResponseInterface|null */ protected $response; @@ -128,6 +128,8 @@ protected function getFilterCaller($filter, string $position): Closure throw new InvalidArgumentException('Invalid filter position passed: ' . $position); } + $filterInstances = []; + if ($filter instanceof FilterInterface) { $filterInstances = [$filter]; } @@ -145,8 +147,6 @@ protected function getFilterCaller($filter, string $position): Closure $filterClasses = [$filter]; } - $filterInstances = []; - foreach ($filterClasses as $class) { // Get an instance $filter = new $class(); diff --git a/system/Throttle/Throttler.php b/system/Throttle/Throttler.php index fba7665de4a8..ce9d673b6f6a 100644 --- a/system/Throttle/Throttler.php +++ b/system/Throttle/Throttler.php @@ -55,7 +55,7 @@ class Throttler implements ThrottlerInterface /** * Timestamp to use (during testing) * - * @var int + * @var int|null */ protected $testTime; diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index c74a825b1bcf..93241798b548 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1454 errors +# total 1446 errors includes: - argument.type.neon @@ -12,7 +12,6 @@ includes: - method.notFound.neon - missingType.iterableValue.neon - missingType.parameter.neon - - nullCoalesce.property.neon - property.defaultValue.neon - property.nonObject.neon - property.notFound.neon diff --git a/utils/phpstan-baseline/nullCoalesce.property.neon b/utils/phpstan-baseline/nullCoalesce.property.neon deleted file mode 100644 index a5889293f5fa..000000000000 --- a/utils/phpstan-baseline/nullCoalesce.property.neon +++ /dev/null @@ -1,38 +0,0 @@ -# total 8 errors - -parameters: - ignoreErrors: - - - message: '#^Property CodeIgniter\\Files\\File\:\:\$size \(int\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../system/Files/File.php - - - - message: '#^Property CodeIgniter\\HTTP\\Files\\UploadedFile\:\:\$error \(int\) on left side of \?\? is not nullable\.$#' - count: 2 - path: ../../system/HTTP/Files/UploadedFile.php - - - - message: '#^Property CodeIgniter\\HTTP\\Message\:\:\$protocolVersion \(string\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../system/HTTP/Message.php - - - - message: '#^Property CodeIgniter\\HTTP\\URI\:\:\$fragment \(string\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../system/HTTP/URI.php - - - - message: '#^Property CodeIgniter\\Throttle\\Throttler\:\:\$testTime \(int\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../system/Throttle/Throttler.php - - - - message: '#^Property CodeIgniter\\Test\\FilterTestTraitTest\:\:\$request \(CodeIgniter\\HTTP\\RequestInterface\) on left side of \?\?\= is not nullable\.$#' - count: 1 - path: ../../tests/system/Test/FilterTestTraitTest.php - - - - message: '#^Property CodeIgniter\\Test\\FilterTestTraitTest\:\:\$response \(CodeIgniter\\HTTP\\ResponseInterface\) on left side of \?\?\= is not nullable\.$#' - count: 1 - path: ../../tests/system/Test/FilterTestTraitTest.php