Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test against PHP 8.4 #378

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ jobs:
- operating-system: 'ubuntu-latest'
php-version: '8.3'

- operating-system: 'ubuntu-latest'
php-version: '8.4'

- operating-system: 'windows-latest'
php-version: '8.3'
php-version: '8.4'
job-description: 'on Windows'

- operating-system: 'macos-latest'
php-version: '8.3'
php-version: '8.4'
job-description: 'on macOS'

name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"phpunit/phpunit": "^9",
"amphp/http-server": "^3",
"kelunik/link-header-rfc5988": "^1",
"psalm/phar": "~5.23",
"laminas/laminas-diactoros": "^2.3"
"psalm/phar": "*",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version will be 6 but different regarding the PHP version.

Copy link
Contributor

@danog danog Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should at least require the latest ^6.8.5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you read the message I wrote just above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and your assumption is wrong: you should always require the latest available version of Psalm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The composer.json of psalm/phar does not allow this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, just require psalm 6.8.5

"laminas/laminas-diactoros": "^3.5.0"
},
"suggest": {
"ext-zlib": "Allows using compression for response bodies.",
Expand Down
2 changes: 1 addition & 1 deletion examples/pagination/1-iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require __DIR__ . '/../.helper/functions.php';

class GitHubApi
final class GitHubApi
{
private HttpClient $httpClient;

Expand Down
4 changes: 2 additions & 2 deletions examples/pagination/2-iterator-batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

require __DIR__ . '/../.helper/functions.php';

class GitHubApi
final class GitHubApi
{
private HttpClient $httpClient;

Expand All @@ -36,7 +36,7 @@ public function getEvents(string $organization): iterable
$events = json_decode($json);
yield $events;

$links = parseLinks($response->getHeader('link'));
$links = parseLinks($response->getHeader('link') ?? '');
$next = $links->getByRel('next');

if ($next) {
Expand Down
1 change: 1 addition & 0 deletions examples/streaming/1-large-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function formatBytes(int $size, int $precision = 2): string
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
1 change: 1 addition & 0 deletions examples/streaming/2-http1-http2.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function fetch(string $uri, array $protocolVersions): void
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
1 change: 1 addition & 0 deletions examples/streaming/3-large-response-slow-read.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function formatBytes(int $size, int $precision = 2): string
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
29 changes: 23 additions & 6 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
phpVersion="8.1"
resolveFromConfigFile="true"
rememberPropertyAssignmentsAfterCall="false"
ensureOverrideAttribute="false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set this to true, override attributes are recommended adn compatible with all PHP versions if the symfony/polyfill-php83 packages required

findUnusedCode="false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a library, everything is unused code!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, public code must be marked with @api, the remaining code is private, unused code.

Copy link
Member

@bwoebi bwoebi Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danog I disagree - in a library everything is api, unless it's marked @internal, or is a private method.
This is littering the code with unnecessary annotations.
This brings no value as is, as I'm going to be only interested in whether my internal code is dead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this config off unless psalm offers a way to "default-mark" everything non-internal & non-private as API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with default-marking everything non-internal and non-private as API is with non-library codebases (that have no public surface apart from API controllers and other entry points).

Some not so clean library codebases have the same problem as well, where internal details are needlessly exposed as public and not marked as internal.

Explicitly marking public API with @api solves both issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danog I think it would be a good thing to make that configurable in psalm. libraryAssumeApi="true" or such.

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude"
>
<projectFiles>
<directory name="examples"/>
Expand All @@ -24,6 +27,20 @@
</errorLevel>
</StringIncrement>

<ImplicitToStringCast>
<errorLevel type="suppress">
<directory name="examples"/>
<directory name="src"/>
</errorLevel>
</ImplicitToStringCast>

<InvalidOperand>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't suppress this at a project level

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vimeo/psalm#11329 will fix what you're (incorrectly) trying to fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not only that. The code often do some float * int, which is perfectly fine, btw string . float is also ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have issues with that, just set strictBinaryOperands="false", do not suppress the issue as it also covers valid errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need lower versions of psalm for php versions compatibility. It would not work anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm is capable of running scans for versions down to php 5.4 on php 8.4, just pass the correct PHP version using the --php-version parameter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm scans should always run on PHP 8.4.4 or above to avoid platform bugs, to target lower versions of PHP simply use the --php-version parameter.

<errorLevel type="suppress">
<directory name="examples"/>
<directory name="src"/>
</errorLevel>
</InvalidOperand>

<DuplicateClass>
<errorLevel type="suppress">
<directory name="examples"/>
Expand All @@ -42,12 +59,6 @@
</errorLevel>
</DocblockTypeContradiction>

<MissingClosureParamType>
<errorLevel type="suppress">
<directory name="src"/>
</errorLevel>
</MissingClosureParamType>

<MissingClosureReturnType>
<errorLevel type="suppress">
<directory name="src" />
Expand All @@ -59,5 +70,11 @@
<directory name="src" />
</errorLevel>
</RiskyTruthyFalsyComparison>

<InvalidReturnType>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't suppress this at the file level

<errorLevel type="suppress">
<file name="src/Connection/Internal/Http1Parser.php" />
</errorLevel>
</InvalidReturnType>
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Connection/Internal/Http1Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ private function parseRawHeaders(string $rawHeaders): array
$rawHeaders = \preg_replace("/\r\n[\x20\t]++/", ' ', $rawHeaders);
}

\assert($rawHeaders !== null);

try {
$headers = Rfc7230::parseHeaderPairs($rawHeaders);
$headerMap = mapHeaderPairs($headers);
Expand Down
1 change: 1 addition & 0 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ public function request(Request $request, Cancellation $cancellation, Stream $st
$this->writeFrame(Http2Parser::CONTINUATION, Http2Parser::NO_FLAG, $streamId, $headerChunk)->ignore();
}

\assert($lastChunk !== null);
$this->writeFrame(Http2Parser::CONTINUATION, $flag, $streamId, $lastChunk)->await();
} else {
$this->writeFrame(Http2Parser::HEADERS, $flag, $streamId, $headers)->await();
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LogHttpArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function writeLog(Response $response): void
$fileHandle->seek(-3, Whence::Current);
}

$json = \json_encode(self::formatEntry($response));
$json = \json_encode(self::formatEntry($response), flags: JSON_THROW_ON_ERROR);

$fileHandle->write(($firstEntry ? '' : ',') . $json . ']}}');

Expand Down
2 changes: 2 additions & 0 deletions src/Interceptor/FollowRedirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private static function removeDotSegments(string $input): string
$patternE = ',(/*[^/]*),';

while ($input !== '') {
\assert($input !== null);
if (\preg_match($patternA, $input)) {
$input = \preg_replace($patternA, '', $input);
} elseif (\preg_match($patternB1, $input, $match) || \preg_match($patternB2, $input, $match)) {
Expand All @@ -80,6 +81,7 @@ private static function removeDotSegments(string $input): string
$input = \preg_replace(',^' . \preg_quote($initialSegment, ',') . ',', '', $input, 1);
$output .= $initialSegment;
}
\assert($output !== null);
}

return $output;
Expand Down
3 changes: 3 additions & 0 deletions src/Interceptor/RetryRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function request(
DelegateHttpClient $httpClient
): Response {
$attempt = 1;
$exception = null;

do {
$clonedRequest = clone $request;
Expand All @@ -43,6 +44,8 @@ public function request(
}
} while ($attempt++ <= $this->retryLimit);

\assert($exception !== null);

throw $exception;
}
}
3 changes: 3 additions & 0 deletions src/Interceptor/TooManyRedirectsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Response;

/**
* @api
*/
class TooManyRedirectsException extends HttpException
{
private Response $response;
Expand Down
Loading