Skip to content

Commit

Permalink
Merge pull request #200 from samsonasik/update-to-php81-syntax
Browse files Browse the repository at this point in the history
Update to latest PHP 8.1 syntax
  • Loading branch information
gsteel authored Nov 3, 2024
2 parents 649d8ae + d5f0e85 commit df90c35
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/RelativeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
final class RelativeStream implements StreamInterface, Stringable
{
private int $offset;
private readonly int $offset;

public function __construct(private StreamInterface $decoratedStream, ?int $offset)
public function __construct(private readonly StreamInterface $decoratedStream, ?int $offset)
{
$this->offset = (int) $offset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function fromGlobals(
?array $files = null,
?FilterServerRequestInterface $requestFilter = null
): ServerRequestInterface {
$requestFilter = $requestFilter ?? FilterUsingXForwardedHeaders::trustReservedSubnets();
$requestFilter ??= FilterUsingXForwardedHeaders::trustReservedSubnets();

$server = normalizeServer(
$server ?? $_SERVER,
Expand Down
6 changes: 4 additions & 2 deletions src/ServerRequestFilter/FilterUsingXForwardedHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ final class FilterUsingXForwardedHeaders implements FilterServerRequestInterface
* @param list<non-empty-string> $trustedProxies
* @param list<FilterUsingXForwardedHeaders::HEADER_*> $trustedHeaders
*/
private function __construct(private array $trustedProxies = [], private array $trustedHeaders = [])
{
private function __construct(
private readonly array $trustedProxies = [],
private readonly array $trustedHeaders = []
) {
}

public function __invoke(ServerRequestInterface $request): ServerRequestInterface
Expand Down
8 changes: 4 additions & 4 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class UploadedFile implements UploadedFileInterface
UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',
];

private int $error;
private readonly int $error;

private ?string $file = null;

Expand All @@ -58,10 +58,10 @@ class UploadedFile implements UploadedFileInterface
*/
public function __construct(
$streamOrFile,
private ?int $size,
private readonly ?int $size,
int $errorStatus,
private ?string $clientFilename = null,
private ?string $clientMediaType = null
private readonly ?string $clientFilename = null,
private readonly ?string $clientMediaType = null
) {
if ($errorStatus === UPLOAD_ERR_OK) {
if (is_string($streamOrFile)) {
Expand Down
2 changes: 1 addition & 1 deletion src/UriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private static function marshalHostAndPort(array $server, array $headers): array
private static function marshalIpv6HostAndPort(array $server, ?int $port): array
{
$host = '[' . (string) $server['SERVER_ADDR'] . ']';
$port = $port ?? 80;
$port ??= 80;
$portSeparatorPos = strrpos($host, ':');

if (false === $portSeparatorPos) {
Expand Down
2 changes: 1 addition & 1 deletion test/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function testReturnsFilteredRequestBasedOnRequestFilterProvided(): void
{
$expectedRequest = new ServerRequest();
$filter = new class ($expectedRequest) implements FilterServerRequestInterface {
public function __construct(private ServerRequestInterface $request)
public function __construct(private readonly ServerRequestInterface $request)
{
}

Expand Down

0 comments on commit df90c35

Please sign in to comment.