Skip to content

Commit 1759433

Browse files
committed
Support PHP 8.4+
1 parent 77cc0f3 commit 1759433

27 files changed

+43
-78
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
php-version:
1414
- "8.2"
1515
- "8.3"
16+
- "8.4"
1617
steps:
1718
- name: Checkout
1819
uses: actions/checkout@v4

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ test-container-83:
4343
@-docker-compose run --rm app83 bash
4444
@docker-compose down -v
4545

46+
.PHONY: test-container-84
47+
test-container-84:
48+
@-docker-compose run --rm app84 bash
49+
@docker-compose down -v
50+
4651
.PHONY: lint
4752
lint:
4853
@XDEBUG_MODE=off phpcs -s

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

88
The **icanboogie/http** package provides a foundation to handle HTTP requests, with representations

lib/AuthenticationRequired.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AuthenticationRequired extends ClientError implements SecurityError
2828
public function __construct(
2929
string $message = self::DEFAULT_MESSAGE,
3030
int $code = ResponseStatus::STATUS_UNAUTHORIZED,
31-
Throwable $previous = null
31+
?Throwable $previous = null
3232
) {
3333
parent::__construct($message, $code, $previous);
3434
}

lib/ClientError.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class ClientError extends \Exception implements Exception
2424
* @inheritdoc
2525
*/
2626
public function __construct(
27-
string $message = null,
27+
?string $message = null,
2828
int $code = ResponseStatus::STATUS_BAD_REQUEST,
29-
Throwable $previous = null
29+
?Throwable $previous = null
3030
) {
3131
parent::__construct($message, $code, $previous);
3232
}

lib/File.php

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the ICanBoogie package.
5-
*
6-
* (c) Olivier Laviale <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace ICanBoogie\HTTP;
134

145
use ICanBoogie\Accessor\AccessorTrait;
@@ -37,8 +28,8 @@
3728
*
3829
* @property-read string $name Name of the file.
3930
* @property-read string $type MIME type of the file.
40-
* @property-read string $size Size of the file.
41-
* @property-read string $error Error code, one of `UPLOAD_ERR_*`.
31+
* @property-read int|false $size Size of the file.
32+
* @property-read int|null $error Error code, one of `UPLOAD_ERR_*`.
4233
* @property-read string $error_message A formatted message representing the error.
4334
* @property-read string $pathname Pathname of the file.
4435
* @property-read string $extension The extension of the file. If any, the dot is included e.g.
@@ -116,17 +107,15 @@ private static function filter_initial_properties(array $properties): array
116107
*
117108
* @param string $format The format of the string.
118109
* @param array $args The arguments.
119-
* @param array $options Some options.
120110
*
121111
* @return FormattedString|string
122112
*/
123113
private static function format(
124114
string $format,
125115
array $args = [],
126-
array $options = []
127116
): string|FormattedString {
128-
if (class_exists(FormattedString::class, true)) {
129-
return new FormattedString($format, $args, $options);
117+
if (class_exists(FormattedString::class)) {
118+
return new FormattedString($format, $args);
130119
}
131120

132121
return format($format, $args); // @codeCoverageIgnore

lib/FileInfo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FileInfo
6464
* @return string The MIME type of the file, or `application/octet-stream` if it could not
6565
* be determined.
6666
*/
67-
public static function resolve_type(string $pathname, string &$extension = null): string
67+
public static function resolve_type(string $pathname, ?string &$extension = null): string
6868
{
6969
$extension = '.' . \strtolower(\pathinfo($pathname, PATHINFO_EXTENSION));
7070
$types = self::TYPES;

lib/FileResponse.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the ICanBoogie package.
5-
*
6-
* (c) Olivier Laviale <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace ICanBoogie\HTTP;
134

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

335-
private function ensure_etag(): string
336-
{
337-
return $this->headers->etag ??= $this->make_etag();
338-
}
339-
340326
/**
341327
* If the date returned by the parent is empty the method returns a date created from
342328
* {@link DEFAULT_EXPIRES}.
@@ -349,7 +335,7 @@ protected function get_expires(): Headers\Date
349335
return $expires;
350336
}
351337

352-
return Headers\Date::from(self::DEFAULT_EXPIRES); // @phpstan-ignore-line
338+
return Headers\Date::from(self::DEFAULT_EXPIRES);
353339
}
354340

355341
/**

lib/ForceRedirect.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ForceRedirect extends \Exception implements Exception
2525
public function __construct(
2626
public readonly string $location,
2727
int $code = ResponseStatus::STATUS_FOUND,
28-
Throwable $previous = null
28+
?Throwable $previous = null
2929
) {
3030
parent::__construct($this->format_message($location), $code, $previous);
3131
}

lib/Headers/CacheControl.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* echo $cc; // no-cache, no-store, must-revalidate
4646
* </pre>
4747
*
48-
* @property bool $cacheable
48+
* @property bool|string|null $cacheable
4949
*
5050
* @see http://tools.ietf.org/html/rfc2616#section-14.9
5151
*/
@@ -169,8 +169,6 @@ public static function from(string|self|null $source): self
169169
* Scope: request, response.
170170
*
171171
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
172-
*
173-
* @var string|null
174172
*/
175173
private ?string $cacheable = null;
176174

@@ -290,7 +288,7 @@ private function set_cacheable(bool|string|null $value): void
290288
/**
291289
* If they are defined, the object is initialized with the cache directives.
292290
*/
293-
public function __construct(string $cache_directives = null)
291+
public function __construct(?string $cache_directives = null)
294292
{
295293
if ($cache_directives) {
296294
$this->modify($cache_directives);

lib/Headers/ContentDisposition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ContentDisposition extends Header
4141
*
4242
* @inheritdoc
4343
*/
44-
public function __construct(string $value = null, array $attributes = [])
44+
public function __construct(?string $value = null, array $attributes = [])
4545
{
4646
$this->parameters['filename'] = new HeaderParameter('filename');
4747

lib/Headers/ContentType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ContentType extends Header
4343
*
4444
* @inheritdoc
4545
*/
46-
public function __construct(string $value = null, array $attributes = [])
46+
public function __construct(?string $value = null, array $attributes = [])
4747
{
4848
$this->parameters['charset'] = new HeaderParameter('charset');
4949

lib/Headers/Date.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the ICanBoogie package.
5-
*
6-
* (c) Olivier Laviale <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace ICanBoogie\HTTP\Headers;
134

145
use DateTimeInterface;
@@ -27,8 +18,7 @@ class Date extends DateTime
2718
public static function from(
2819
self|\DateTime|string|null $source,
2920
DateTimeZone|string|null $timezone = null
30-
): static
31-
{
21+
): static {
3222
if ($source === null) {
3323
return static::none();
3424
}
@@ -62,7 +52,7 @@ public function __construct($time = 'now', $timezone = null)
6252
*
6353
* @inheritdoc
6454
*/
65-
public function __toString()
55+
public function __toString(): string
6656
{
6757
return $this->is_empty ? '' : $this->utc->as_rfc1123;
6858
}

lib/MethodNotAllowed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MethodNotAllowed extends ClientError implements Exception
2020
{
2121
public function __construct(
2222
public readonly string $method,
23-
Throwable $previous = null
23+
?Throwable $previous = null
2424
) {
2525
parent::__construct(
2626
"Method not allowed: $method.",

lib/NotFound.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NotFound extends ClientError implements Exception
2626
public function __construct(
2727
string $message = self::DEFAULT_MESSAGE,
2828
int $code = ResponseStatus::STATUS_NOT_FOUND,
29-
Throwable $previous = null
29+
?Throwable $previous = null
3030
) {
3131
parent::__construct($message, $code, $previous);
3232
}

lib/PermissionRequired.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PermissionRequired extends ClientError implements SecurityError
2626
public function __construct(
2727
string $message = self::DEFAULT_MESSAGE,
2828
int $code = ResponseStatus::STATUS_UNAUTHORIZED,
29-
Throwable $previous = null
29+
?Throwable $previous = null
3030
) {
3131
parent::__construct($message, $code, $previous);
3232
}

lib/RecoverEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RecoverEvent extends Event
2525
public function __construct(
2626
Throwable &$sender,
2727
public readonly Request $request,
28-
Response &$response = null
28+
?Response &$response = null
2929
) {
3030
$this->response = &$response;
3131
$this->exception = &$sender;

lib/Responder/WithEvent/BeforeRespondEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BeforeRespondEvent extends Event
2424

2525
public function __construct(
2626
public readonly Request $request,
27-
Response &$response = null
27+
?Response &$response = null
2828
) {
2929
$this->response = &$response;
3030

lib/Responder/WithEvent/RespondEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RespondEvent extends Event
2424

2525
public function __construct(
2626
public readonly Request $request,
27-
Response &$response = null
27+
?Response &$response = null
2828
) {
2929
$this->response = &$response;
3030

lib/ServerError.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class ServerError extends \Exception implements Exception
2424
* @inheritdoc
2525
*/
2626
public function __construct(
27-
string $message = null,
27+
?string $message = null,
2828
int $code = ResponseStatus::STATUS_INTERNAL_SERVER_ERROR,
29-
Throwable $previous = null
29+
?Throwable $previous = null
3030
) {
3131
parent::__construct($message, $code, $previous);
3232
}

lib/ServiceUnavailable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ServiceUnavailable extends ServerError implements Exception
2828
public function __construct(
2929
string $message = self::DEFAULT_MESSAGE,
3030
int $code = ResponseStatus::STATUS_SERVICE_UNAVAILABLE,
31-
Throwable $previous = null
31+
?Throwable $previous = null
3232
) {
3333
parent::__construct($message, $code, $previous);
3434
}

lib/Status.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ protected function get_message(): string
521521
return $message;
522522
}
523523

524-
public function __construct(int $code = ResponseStatus::STATUS_OK, string $message = null)
524+
public function __construct(int $code = ResponseStatus::STATUS_OK, ?string $message = null)
525525
{
526526
self::assert_code_is_valid($code);
527527

lib/StatusCodeNotValid.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class StatusCodeNotValid extends InvalidArgumentException implements Exception
2323
{
2424
public function __construct(
2525
public readonly int $status_code,
26-
string $message = null,
26+
?string $message = null,
2727
int $code = ResponseStatus::STATUS_INTERNAL_SERVER_ERROR,
28-
Throwable $previous = null
28+
?Throwable $previous = null
2929
) {
3030
parent::__construct($message ?: $this->format_message($status_code), $code, $previous);
3131
}

phpunit.xml

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
<directory>./tests</directory>
1717
</testsuite>
1818
</testsuites>
19+
<source>
20+
<include>
21+
<directory>lib</directory>
22+
</include>
23+
</source>
1924
</phpunit>

tests/FileResponseTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the ICanBoogie package.
5-
*
6-
* (c) Olivier Laviale <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace ICanBoogie\HTTP;
134

145
use ICanBoogie\DateTime;
@@ -259,7 +250,7 @@ public function test_get_is_modified(
259250
bool $expected,
260251
array $request_headers,
261252
false|int $modified_time = false,
262-
string $etag = null
253+
?string $etag = null
263254
): void {
264255
$file = create_file();
265256
if ($modified_time) {

tests/Headers/HeaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class A extends Header
152152
{
153153
public const VALUE_ALIAS = 'type';
154154

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

tests/ResponderProvider/ChainTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function test_chain_with_no_match(): void
4747
$this->assertNull($chain->responder_for_request(Request::from()));
4848
}
4949

50-
public function makeProvider(Responder $responder = null, bool $shouldNotBeCalled = false): ResponderProvider
50+
public function makeProvider(?Responder $responder = null, bool $shouldNotBeCalled = false): ResponderProvider
5151
{
5252
$provider = $this->createMock(ResponderProvider::class);
5353
$provider

0 commit comments

Comments
 (0)