Skip to content

Commit

Permalink
Support PHP 8.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 2, 2024
1 parent 77cc0f3 commit 1759433
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 78 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ test-container-83:
@-docker-compose run --rm app83 bash
@docker-compose down -v

.PHONY: test-container-84
test-container-84:
@-docker-compose run --rm app84 bash
@docker-compose down -v

.PHONY: lint
lint:
@XDEBUG_MODE=off phpcs -s
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Release](https://img.shields.io/packagist/v/icanboogie/http.svg)](https://packagist.org/packages/icanboogie/http)
[![Code Quality](https://img.shields.io/scrutinizer/g/ICanBoogie/HTTP/6.0.svg)](https://scrutinizer-ci.com/g/ICanBoogie/HTTP)
[![Code Coverage](https://img.shields.io/coveralls/ICanBoogie/HTTP.svg)](https://coveralls.io/r/ICanBoogie/HTTP)
[![Code Coverage](https://coveralls.io/repos/github/ICanBoogie/HTTP/badge.svg?branch6.0)](https://coveralls.io/r/ICanBoogie/HTTP?branch=6.0)
[![Packagist](https://img.shields.io/packagist/dt/icanboogie/http.svg)](https://packagist.org/packages/icanboogie/http)

The **icanboogie/http** package provides a foundation to handle HTTP requests, with representations
Expand Down
2 changes: 1 addition & 1 deletion lib/AuthenticationRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthenticationRequired extends ClientError implements SecurityError
public function __construct(
string $message = self::DEFAULT_MESSAGE,
int $code = ResponseStatus::STATUS_UNAUTHORIZED,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ClientError.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ClientError extends \Exception implements Exception
* @inheritdoc
*/
public function __construct(
string $message = null,
?string $message = null,
int $code = ResponseStatus::STATUS_BAD_REQUEST,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
19 changes: 4 additions & 15 deletions lib/File.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\HTTP;

use ICanBoogie\Accessor\AccessorTrait;
Expand Down Expand Up @@ -37,8 +28,8 @@
*
* @property-read string $name Name of the file.
* @property-read string $type MIME type of the file.
* @property-read string $size Size of the file.
* @property-read string $error Error code, one of `UPLOAD_ERR_*`.
* @property-read int|false $size Size of the file.
* @property-read int|null $error Error code, one of `UPLOAD_ERR_*`.
* @property-read string $error_message A formatted message representing the error.
* @property-read string $pathname Pathname of the file.
* @property-read string $extension The extension of the file. If any, the dot is included e.g.
Expand Down Expand Up @@ -116,17 +107,15 @@ private static function filter_initial_properties(array $properties): array
*
* @param string $format The format of the string.
* @param array $args The arguments.
* @param array $options Some options.
*
* @return FormattedString|string
*/
private static function format(
string $format,
array $args = [],
array $options = []
): string|FormattedString {
if (class_exists(FormattedString::class, true)) {
return new FormattedString($format, $args, $options);
if (class_exists(FormattedString::class)) {
return new FormattedString($format, $args);
}

return format($format, $args); // @codeCoverageIgnore
Expand Down
2 changes: 1 addition & 1 deletion lib/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FileInfo
* @return string The MIME type of the file, or `application/octet-stream` if it could not
* be determined.
*/
public static function resolve_type(string $pathname, string &$extension = null): string
public static function resolve_type(string $pathname, ?string &$extension = null): string
{
$extension = '.' . \strtolower(\pathinfo($pathname, PATHINFO_EXTENSION));
$types = self::TYPES;
Expand Down
16 changes: 1 addition & 15 deletions lib/FileResponse.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\HTTP;

use ICanBoogie\DateTime;
Expand Down Expand Up @@ -332,11 +323,6 @@ private function make_etag(): string
return self::hash_file($this->file->getPathname());
}

private function ensure_etag(): string
{
return $this->headers->etag ??= $this->make_etag();
}

/**
* If the date returned by the parent is empty the method returns a date created from
* {@link DEFAULT_EXPIRES}.
Expand All @@ -349,7 +335,7 @@ protected function get_expires(): Headers\Date
return $expires;
}

return Headers\Date::from(self::DEFAULT_EXPIRES); // @phpstan-ignore-line
return Headers\Date::from(self::DEFAULT_EXPIRES);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/ForceRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ForceRedirect extends \Exception implements Exception
public function __construct(
public readonly string $location,
int $code = ResponseStatus::STATUS_FOUND,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($this->format_message($location), $code, $previous);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Headers/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* echo $cc; // no-cache, no-store, must-revalidate
* </pre>
*
* @property bool $cacheable
* @property bool|string|null $cacheable
*
* @see http://tools.ietf.org/html/rfc2616#section-14.9
*/
Expand Down Expand Up @@ -169,8 +169,6 @@ public static function from(string|self|null $source): self
* Scope: request, response.
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
*
* @var string|null
*/
private ?string $cacheable = null;

Expand Down Expand Up @@ -290,7 +288,7 @@ private function set_cacheable(bool|string|null $value): void
/**
* If they are defined, the object is initialized with the cache directives.
*/
public function __construct(string $cache_directives = null)
public function __construct(?string $cache_directives = null)
{
if ($cache_directives) {
$this->modify($cache_directives);
Expand Down
2 changes: 1 addition & 1 deletion lib/Headers/ContentDisposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ContentDisposition extends Header
*
* @inheritdoc
*/
public function __construct(string $value = null, array $attributes = [])
public function __construct(?string $value = null, array $attributes = [])
{
$this->parameters['filename'] = new HeaderParameter('filename');

Expand Down
2 changes: 1 addition & 1 deletion lib/Headers/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ContentType extends Header
*
* @inheritdoc
*/
public function __construct(string $value = null, array $attributes = [])
public function __construct(?string $value = null, array $attributes = [])
{
$this->parameters['charset'] = new HeaderParameter('charset');

Expand Down
14 changes: 2 additions & 12 deletions lib/Headers/Date.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\HTTP\Headers;

use DateTimeInterface;
Expand All @@ -27,8 +18,7 @@ class Date extends DateTime
public static function from(
self|\DateTime|string|null $source,
DateTimeZone|string|null $timezone = null
): static
{
): static {
if ($source === null) {
return static::none();
}
Expand Down Expand Up @@ -62,7 +52,7 @@ public function __construct($time = 'now', $timezone = null)
*
* @inheritdoc
*/
public function __toString()
public function __toString(): string
{
return $this->is_empty ? '' : $this->utc->as_rfc1123;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MethodNotAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MethodNotAllowed extends ClientError implements Exception
{
public function __construct(
public readonly string $method,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct(
"Method not allowed: $method.",
Expand Down
2 changes: 1 addition & 1 deletion lib/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NotFound extends ClientError implements Exception
public function __construct(
string $message = self::DEFAULT_MESSAGE,
int $code = ResponseStatus::STATUS_NOT_FOUND,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PermissionRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PermissionRequired extends ClientError implements SecurityError
public function __construct(
string $message = self::DEFAULT_MESSAGE,
int $code = ResponseStatus::STATUS_UNAUTHORIZED,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/RecoverEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RecoverEvent extends Event
public function __construct(
Throwable &$sender,
public readonly Request $request,
Response &$response = null
?Response &$response = null
) {
$this->response = &$response;
$this->exception = &$sender;
Expand Down
2 changes: 1 addition & 1 deletion lib/Responder/WithEvent/BeforeRespondEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BeforeRespondEvent extends Event

public function __construct(
public readonly Request $request,
Response &$response = null
?Response &$response = null
) {
$this->response = &$response;

Expand Down
2 changes: 1 addition & 1 deletion lib/Responder/WithEvent/RespondEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RespondEvent extends Event

public function __construct(
public readonly Request $request,
Response &$response = null
?Response &$response = null
) {
$this->response = &$response;

Expand Down
4 changes: 2 additions & 2 deletions lib/ServerError.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ServerError extends \Exception implements Exception
* @inheritdoc
*/
public function __construct(
string $message = null,
?string $message = null,
int $code = ResponseStatus::STATUS_INTERNAL_SERVER_ERROR,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ServiceUnavailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ServiceUnavailable extends ServerError implements Exception
public function __construct(
string $message = self::DEFAULT_MESSAGE,
int $code = ResponseStatus::STATUS_SERVICE_UNAVAILABLE,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ protected function get_message(): string
return $message;
}

public function __construct(int $code = ResponseStatus::STATUS_OK, string $message = null)
public function __construct(int $code = ResponseStatus::STATUS_OK, ?string $message = null)
{
self::assert_code_is_valid($code);

Expand Down
4 changes: 2 additions & 2 deletions lib/StatusCodeNotValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class StatusCodeNotValid extends InvalidArgumentException implements Exception
{
public function __construct(
public readonly int $status_code,
string $message = null,
?string $message = null,
int $code = ResponseStatus::STATUS_INTERNAL_SERVER_ERROR,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message ?: $this->format_message($status_code), $code, $previous);
}
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>lib</directory>
</include>
</source>
</phpunit>
11 changes: 1 addition & 10 deletions tests/FileResponseTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\HTTP;

use ICanBoogie\DateTime;
Expand Down Expand Up @@ -259,7 +250,7 @@ public function test_get_is_modified(
bool $expected,
array $request_headers,
false|int $modified_time = false,
string $etag = null
?string $etag = null
): void {
$file = create_file();
if ($modified_time) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Headers/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class A extends Header
{
public const VALUE_ALIAS = 'type';

public function __construct($value = null, array $attributes = [])
public function __construct(mixed $value = null, array $attributes = [])
{
$this->parameters['p'] = new HeaderParameter('p');

Expand Down
2 changes: 1 addition & 1 deletion tests/ResponderProvider/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_chain_with_no_match(): void
$this->assertNull($chain->responder_for_request(Request::from()));
}

public function makeProvider(Responder $responder = null, bool $shouldNotBeCalled = false): ResponderProvider
public function makeProvider(?Responder $responder = null, bool $shouldNotBeCalled = false): ResponderProvider
{
$provider = $this->createMock(ResponderProvider::class);
$provider
Expand Down

0 comments on commit 1759433

Please sign in to comment.