Skip to content

Commit 3935162

Browse files
committed
refactor: fix the latent LSP violations in HTTP
1 parent 1d2489c commit 3935162

8 files changed

Lines changed: 10 additions & 29 deletions

File tree

system/HTTP/Files/UploadedFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp
130130
* @param bool $overwrite State for indicating whether to overwrite the previously generated file with the same
131131
* name or not.
132132
*
133-
* @return bool
133+
* @return static
134134
*/
135135
public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
136136
{
@@ -172,7 +172,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
172172
$this->path = $targetPath;
173173
$this->name = basename($destination);
174174

175-
return true;
175+
return $this;
176176
}
177177

178178
/**

system/HTTP/Files/UploadedFileInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp
6262
* @param string $targetPath Path to which to move the uploaded file.
6363
* @param string|null $name the name to rename the file to.
6464
*
65-
* @return bool
65+
* @return static
6666
*
6767
* @throws InvalidArgumentException if the $path specified is invalid.
6868
* @throws RuntimeException on the second or subsequent call to the method.

system/HTTP/IncomingRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class IncomingRequest extends Request
5656
* everything this cares about (and the router, etc) is the portion
5757
* AFTER the baseURL. So, if hosted in a sub-folder this will
5858
* appear different than actual URI path. If you need that use getPath().
59-
*
60-
* @var URI
6159
*/
6260
protected $uri;
6361

system/HTTP/OutgoingRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OutgoingRequest extends Message implements OutgoingRequestInterface
3030
/**
3131
* A URI instance.
3232
*
33-
* @var URI|null
33+
* @var URI
3434
*/
3535
protected $uri;
3636

@@ -40,7 +40,7 @@ class OutgoingRequest extends Message implements OutgoingRequestInterface
4040
*/
4141
public function __construct(
4242
string $method,
43-
?URI $uri = null,
43+
URI $uri,
4444
array $headers = [],
4545
$body = null,
4646
string $version = '1.1',
@@ -109,7 +109,7 @@ public function withMethod($method)
109109
/**
110110
* Retrieves the URI instance.
111111
*
112-
* @return URI|null
112+
* @return URI
113113
*/
114114
public function getUri()
115115
{

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ update your implementations to include the new methods or method changes to ensu
5555
- **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``.
5656
- **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, ``inTransaction()``, and ``transaction()`` methods.
5757
- **HTTP:** ``CodeIgniter\HTTP\ResponseInterface`` now requires the ``stream()`` and ``eventStream()`` methods, which create streaming and SSE responses. See :ref:`streaming-responses`.
58+
- **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.
5859
- **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.
5960
- **Security:** The ``SecurityInterface``'s ``verify()`` method now has a native return type of ``static``.
6061
- **Validation:** ``CodeIgniter\Validation\ValidationInterface`` now requires the ``getValidatedInput()`` method, which returns a ``CodeIgniter\Input\ValidatedInput`` instance.
@@ -73,6 +74,7 @@ Method Signature Changes
7374
- **Config:** ``CodeIgniter\Config\Services::request()`` no longer accepts any parameter.
7475
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
7576
- ``CodeIgniter\Database\Forge::_createTable()`` no longer accepts the deprecated ``$ifNotExists`` parameter. The method signature is now ``_createTable(string $table, array $attributes)``.
77+
- **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``.
7678
- **Model:** ``CodeIgniter\BaseModel`` now requires the ``chunkRows()``, ``chunkById()``, and ``chunkRowsById()`` methods. Custom classes extending ``BaseModel`` directly must implement them.
7779
- **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()``.
7880

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1492 errors
1+
# total 1489 errors
22

33
includes:
44
- argument.type.neon
@@ -8,7 +8,6 @@ includes:
88
- deadCode.unreachable.neon
99
- function.resultUnused.neon
1010
- method.childParameterType.neon
11-
- method.childReturnType.neon
1211
- method.notFound.neon
1312
- missingType.callable.neon
1413
- missingType.iterableValue.neon

utils/phpstan-baseline/method.childReturnType.neon

Lines changed: 0 additions & 13 deletions
This file was deleted.

utils/phpstan-baseline/property.phpDocType.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 41 errors
1+
# total 40 errors
22

33
parameters:
44
ignoreErrors:
@@ -147,11 +147,6 @@ parameters:
147147
count: 1
148148
path: ../../system/HTTP/Files/UploadedFile.php
149149

150-
-
151-
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\.$#'
152-
count: 1
153-
path: ../../system/HTTP/IncomingRequest.php
154-
155150
-
156151
message: '#^PHPDoc type string of property CodeIgniter\\Session\\Handlers\\FileHandler\:\:\$savePath is not the same as PHPDoc type array\<string, mixed\>\|string of overridden property CodeIgniter\\Session\\Handlers\\BaseHandler\:\:\$savePath\.$#'
157152
count: 1

0 commit comments

Comments
 (0)