Skip to content

Commit f1dae53

Browse files
committed
refactor: fix the latent LSP violations in HTTP
1 parent 78510c1 commit f1dae53

8 files changed

Lines changed: 8 additions & 27 deletions

File tree

‎system/HTTP/Files/UploadedFile.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp
123123
* @param bool $overwrite State for indicating whether to overwrite the previously generated file with the same
124124
* name or not.
125125
*
126-
* @return bool
126+
* @return static
127127
*/
128128
public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
129129
{
@@ -165,7 +165,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
165165
$this->path = $targetPath;
166166
$this->name = basename($destination);
167167

168-
return true;
168+
return $this;
169169
}
170170

171171
/**

‎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

@@ -41,7 +41,7 @@ class OutgoingRequest extends Message implements OutgoingRequestInterface
4141
*/
4242
public function __construct(
4343
string $method,
44-
?URI $uri = null,
44+
URI $uri,
4545
array $headers = [],
4646
$body = null,
4747
string $version = '1.1',
@@ -110,7 +110,7 @@ public function withMethod($method)
110110
/**
111111
* Retrieves the URI instance.
112112
*
113-
* @return URI|null
113+
* @return URI
114114
*/
115115
public function getUri()
116116
{

‎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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ parameters:
7777
count: 1
7878
path: ../../system/HTTP/Exceptions/RedirectException.php
7979

80-
-
81-
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\.$#'
82-
count: 1
83-
path: ../../system/HTTP/IncomingRequest.php
84-
8580
-
8681
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\.$#'
8782
count: 1

0 commit comments

Comments
 (0)