Skip to content

Commit 3a56e45

Browse files
committed
Add memory limit to PHPStan command and update return types for PSR-7 v2
1 parent eccadee commit 3a56e45

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
run: composer update --no-interaction --no-progress --prefer-dist
2828

2929
- name: Run PHPStan
30-
run: vendor/bin/phpstan analyse --no-progress
30+
run: vendor/bin/phpstan analyse --no-progress --memory-limit=512M

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
- **`Stream::str2resorce()` renamed** to `Stream::stringToResource()` (private). Materialised detach handle now preserves cursor position.
4242
- **`RequestTrait::updateHostFormUri()` renamed** to `updateHostFromUri()`.
4343
- **HTTP version whitelist widened** to accept `2`, `2.0`, `3`, `3.0` (alongside `1.0` and `1.1`).
44-
- **Native return types added for PSR-7 v2 covariance** on six methods:
44+
- **Native return types added for PSR-7 v2 covariance** on seven methods:
4545
`Stream::close(): void`, `Stream::seek(...): void`, `Stream::rewind(): void`,
4646
`MessageTrait::getHeader($name): array`,
47-
`UploadedFile::getStream(): StreamInterface`, `UploadedFile::moveTo(...): void`.
47+
`UploadedFile::getStream(): StreamInterface`, `UploadedFile::moveTo(...): void`,
48+
`Uri::__toString(): string`.
49+
Required by PHP 7.4 + PSR-7 v2 (`Declaration must be compatible with ...`
50+
fatal at class load); PHP 8.0+ accepted the untyped signatures silently
51+
but the fix is uniform across all supported PHP versions.
4852
No call-site change is required (the existing `@return` PHPDoc lines
4953
already documented these types), but subclass overrides must match the
5054
new signatures or stay untyped.
@@ -60,6 +64,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6064
- `UploadedFile::moveTo()` survives partial-write iterations and retries until the chunk is flushed.
6165
- `ServerRequest::normalizeFiles()` recurses into arbitrarily nested file input names (`file[parent][child][…]`).
6266
- `send_request()` (global helper) requires a URL when the first arg is a method string instead of silently sending to `null`.
67+
- `tests/Unit/FixtureServerTrait` exposes the loopback host through a static method instead of a trait constant, so the unit suite loads on PHP 7.4 / 8.0 / 8.1 (trait constants are a PHP 8.2+ feature).
68+
- `static-analysis.yml` workflow now runs PHPStan with `--memory-limit=512M`, matching the `composer phpstan` script — the default 128 MiB triggered an OOM under PHP 7.4 during local reproduction.
6369

6470
### Removed (in addition to breaking changes above)
6571

docs/upgrade-guide.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ The `target=null` (pure in-memory string) backend used to *prepend* at position
142142

143143
### 15. Native return types added for PSR-7 v2 covariance
144144

145-
Six methods gained explicit language-level return types to satisfy the tightened `psr/http-message: ^2.0` contract:
145+
Seven methods gained explicit language-level return types to satisfy the tightened `psr/http-message: ^2.0` contract:
146146

147147
| Method | Added return type |
148148
|----------------------------------------------|---------------------|
@@ -152,9 +152,14 @@ Six methods gained explicit language-level return types to satisfy the tightened
152152
| `MessageTrait::getHeader($name)` | `: array` |
153153
| `UploadedFile::getStream()` | `: StreamInterface` |
154154
| `UploadedFile::moveTo($targetPath)` | `: void` |
155+
| `Uri::__toString()` | `: string` |
155156

156157
Existing PHPDoc `@return` lines already documented these types — only the runtime signature changed. **No call-site code needs to change.**
157158

159+
> **Why this matters most on PHP 7.4 + PSR-7 v2.** PHP 7.4 enforces return-type covariance strictly: an untyped implementation does not satisfy a typed interface return, and the result is a fatal at class load:
160+
> *"Declaration of InitPHP\HTTP\Message\Uri::__toString() must be compatible with Psr\Http\Message\UriInterface::__toString(): string"*.
161+
> PHP 8.0+ accepted the older signatures silently. The fix is uniform across all supported PHP versions.
162+
158163
If you **extended** any of these classes and **overrode** one of those methods, your override's signature must now match the new return type (or stay untyped — PHP allows that). An override declaring a different return type will fail at class load with a covariance error.
159164

160165
---

src/Message/Uri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct(string $uri = '')
9191
*
9292
* @return string
9393
*/
94-
public function __toString()
94+
public function __toString(): string
9595
{
9696
return self::createUriString($this->scheme, $this->getAuthority(), $this->path, $this->query, $this->fragment);
9797
}

0 commit comments

Comments
 (0)