From 39351627545b76f94515a4fe728851b594bc6d6e Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 14 Aug 2026 19:04:53 +0800 Subject: [PATCH] refactor: fix the latent LSP violations in `HTTP` --- system/HTTP/Files/UploadedFile.php | 4 ++-- system/HTTP/Files/UploadedFileInterface.php | 2 +- system/HTTP/IncomingRequest.php | 2 -- system/HTTP/OutgoingRequest.php | 6 +++--- user_guide_src/source/changelogs/v4.8.0.rst | 2 ++ utils/phpstan-baseline/loader.neon | 3 +-- utils/phpstan-baseline/method.childReturnType.neon | 13 ------------- utils/phpstan-baseline/property.phpDocType.neon | 7 +------ 8 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 utils/phpstan-baseline/method.childReturnType.neon diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index be2b74c2025c..5e0a44a0376c 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -130,7 +130,7 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp * @param bool $overwrite State for indicating whether to overwrite the previously generated file with the same * name or not. * - * @return bool + * @return static */ public function move(string $targetPath, ?string $name = null, bool $overwrite = false) { @@ -172,7 +172,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite = $this->path = $targetPath; $this->name = basename($destination); - return true; + return $this; } /** diff --git a/system/HTTP/Files/UploadedFileInterface.php b/system/HTTP/Files/UploadedFileInterface.php index 6e849d04a76b..bf4ded5e8952 100644 --- a/system/HTTP/Files/UploadedFileInterface.php +++ b/system/HTTP/Files/UploadedFileInterface.php @@ -62,7 +62,7 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp * @param string $targetPath Path to which to move the uploaded file. * @param string|null $name the name to rename the file to. * - * @return bool + * @return static * * @throws InvalidArgumentException if the $path specified is invalid. * @throws RuntimeException on the second or subsequent call to the method. diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 283c559a63ed..3692b7b37680 100644 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -56,8 +56,6 @@ class IncomingRequest extends Request * everything this cares about (and the router, etc) is the portion * AFTER the baseURL. So, if hosted in a sub-folder this will * appear different than actual URI path. If you need that use getPath(). - * - * @var URI */ protected $uri; diff --git a/system/HTTP/OutgoingRequest.php b/system/HTTP/OutgoingRequest.php index 11ec0b13e89c..144abc3d7637 100644 --- a/system/HTTP/OutgoingRequest.php +++ b/system/HTTP/OutgoingRequest.php @@ -30,7 +30,7 @@ class OutgoingRequest extends Message implements OutgoingRequestInterface /** * A URI instance. * - * @var URI|null + * @var URI */ protected $uri; @@ -40,7 +40,7 @@ class OutgoingRequest extends Message implements OutgoingRequestInterface */ public function __construct( string $method, - ?URI $uri = null, + URI $uri, array $headers = [], $body = null, string $version = '1.1', @@ -109,7 +109,7 @@ public function withMethod($method) /** * Retrieves the URI instance. * - * @return URI|null + * @return URI */ public function getUri() { diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index 7f2bcb2d2155..fb8c97dde69b 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -55,6 +55,7 @@ update your implementations to include the new methods or method changes to ensu - **Cache:** ``CodeIgniter\Cache\CacheInterface::remember()`` now accepts a TTL callable. Custom implementations of ``CacheInterface`` must update the ``$ttl`` parameter type from ``int`` to ``callable|int``. - **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, ``inTransaction()``, and ``transaction()`` methods. - **HTTP:** ``CodeIgniter\HTTP\ResponseInterface`` now requires the ``stream()`` and ``eventStream()`` methods, which create streaming and SSE responses. See :ref:`streaming-responses`. +- **HTTP:** ``CodeIgniter\HTTP\Files\UploadedFileInterface::move()`` now returns ``static`` instead of ``bool``. The previous ``bool`` return was incompatible with ``CodeIgniter\Files\File::move()``, which ``UploadedFile`` extends, so no implementation could satisfy both. - **Logging:** ``CodeIgniter\Log\Handlers\HandlerInterface::handle()`` now requires a third parameter ``array $context = []``. Any custom log handler that overrides ``handle()`` - whether implementing ``HandlerInterface`` directly or extending a built-in handler class - must add the parameter to its ``handle()`` method signature. - **Security:** The ``SecurityInterface``'s ``verify()`` method now has a native return type of ``static``. - **Validation:** ``CodeIgniter\Validation\ValidationInterface`` now requires the ``getValidatedInput()`` method, which returns a ``CodeIgniter\Input\ValidatedInput`` instance. @@ -73,6 +74,7 @@ Method Signature Changes - **Config:** ``CodeIgniter\Config\Services::request()`` no longer accepts any parameter. - **Database:** The following methods have had their signatures updated to remove deprecated parameters: - ``CodeIgniter\Database\Forge::_createTable()`` no longer accepts the deprecated ``$ifNotExists`` parameter. The method signature is now ``_createTable(string $table, array $attributes)``. +- **HTTP:** ``CodeIgniter\HTTP\OutgoingRequest::__construct()`` now requires the ``$uri`` parameter, which was previously ``?URI $uri = null``. Omitting it never worked, as the constructor dereferences the URI to set the ``Host`` header. Consequently ``OutgoingRequest::getUri()`` now returns ``URI`` instead of ``URI|null``, matching ``OutgoingRequestInterface``. - **Model:** ``CodeIgniter\BaseModel`` now requires the ``chunkRows()``, ``chunkById()``, and ``chunkRowsById()`` methods. Custom classes extending ``BaseModel`` directly must implement them. - **Session:** The ``$max_lifetime`` parameter of the following ``gc()`` methods now has the native ``int`` type, matching ``SessionHandlerInterface``: ``ArrayHandler::gc()``, ``DatabaseHandler::gc()``, ``FileHandler::gc()``, ``MemcachedHandler::gc()``, ``PostgreHandler::gc()``, ``RedisHandler::gc()``. diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 817b59589b65..43ce97a73baf 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1492 errors +# total 1489 errors includes: - argument.type.neon @@ -8,7 +8,6 @@ includes: - deadCode.unreachable.neon - function.resultUnused.neon - method.childParameterType.neon - - method.childReturnType.neon - method.notFound.neon - missingType.callable.neon - missingType.iterableValue.neon diff --git a/utils/phpstan-baseline/method.childReturnType.neon b/utils/phpstan-baseline/method.childReturnType.neon deleted file mode 100644 index 6e6a320a6177..000000000000 --- a/utils/phpstan-baseline/method.childReturnType.neon +++ /dev/null @@ -1,13 +0,0 @@ -# total 2 errors - -parameters: - ignoreErrors: - - - message: '#^Return type \(bool\) of method CodeIgniter\\HTTP\\Files\\UploadedFile\:\:move\(\) should be compatible with return type \(CodeIgniter\\Files\\File\) of method CodeIgniter\\Files\\File\:\:move\(\)$#' - count: 1 - path: ../../system/HTTP/Files/UploadedFile.php - - - - message: '#^Return type \(CodeIgniter\\HTTP\\URI\|null\) of method CodeIgniter\\HTTP\\OutgoingRequest\:\:getUri\(\) should be covariant with return type \(CodeIgniter\\HTTP\\URI\) of method CodeIgniter\\HTTP\\OutgoingRequestInterface\:\:getUri\(\)$#' - count: 1 - path: ../../system/HTTP/OutgoingRequest.php diff --git a/utils/phpstan-baseline/property.phpDocType.neon b/utils/phpstan-baseline/property.phpDocType.neon index c9f237db3c76..8a87cb12c3ae 100644 --- a/utils/phpstan-baseline/property.phpDocType.neon +++ b/utils/phpstan-baseline/property.phpDocType.neon @@ -1,4 +1,4 @@ -# total 41 errors +# total 40 errors parameters: ignoreErrors: @@ -147,11 +147,6 @@ parameters: count: 1 path: ../../system/HTTP/Files/UploadedFile.php - - - message: '#^PHPDoc type CodeIgniter\\HTTP\\URI of property CodeIgniter\\HTTP\\IncomingRequest\:\:\$uri is not the same as PHPDoc type CodeIgniter\\HTTP\\URI\|null of overridden property CodeIgniter\\HTTP\\OutgoingRequest\:\:\$uri\.$#' - count: 1 - path: ../../system/HTTP/IncomingRequest.php - - message: '#^PHPDoc type string of property CodeIgniter\\Session\\Handlers\\FileHandler\:\:\$savePath is not the same as PHPDoc type array\\|string of overridden property CodeIgniter\\Session\\Handlers\\BaseHandler\:\:\$savePath\.$#' count: 1