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

use non-deprecated methods with league/uri 7 #369

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
24 changes: 17 additions & 7 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
$this->hasTimeout = false;

if ($stream->trailers) {
if ($stream->expectedLength && $stream->received !== $stream->expectedLength) {

Check failure on line 311 in src/Connection/Internal/Http2ConnectionProcessor.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

RiskyTruthyFalsyComparison

src/Connection/Internal/Http2ConnectionProcessor.php:311:17: RiskyTruthyFalsyComparison: Operand of type int|null contains type int, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 311 in src/Connection/Internal/Http2ConnectionProcessor.php

View workflow job for this annotation

GitHub Actions / PHP 8.0

RiskyTruthyFalsyComparison

src/Connection/Internal/Http2ConnectionProcessor.php:311:17: RiskyTruthyFalsyComparison: Operand of type int|null contains type int, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
$diff = $stream->expectedLength - $stream->received;
$this->handleStreamException(new Http2StreamException(
"Content length mismatch: " . \abs($diff) . ' bytes ' . ($diff > 0 ? ' missing' : 'too much'),
Expand Down Expand Up @@ -647,13 +647,23 @@
}

try {
$uri = Uri\Http::createFromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
if (\method_exists(Uri\Http::class, 'fromComponents')) {
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
} else {
$uri = Uri\Http::createFromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
}
} catch (\Exception $exception) {
$this->handleConnectionException(new Http2ConnectionException(
"Invalid push URI",
Expand Down
6 changes: 5 additions & 1 deletion src/Interceptor/FollowRedirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ private function getRedirectUri(Response $response): ?PsrUri
$location = $response->getHeader('location');
\assert($location !== null);

$locationUri = Uri\Http::createFromString($location);
if (\method_exists(Uri\Http::class, 'new')) {
$locationUri = Uri\Http::new($location);
} else {
$locationUri = Uri\Http::createFromString($location);
}
} catch (\Exception $e) {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Interceptor/MatchOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public function request(
private function checkOrigin(string $origin): string
{
try {
$originUri = Http::createFromString($origin);
if (\method_exists(Http::class, 'new')) {
$originUri = Http::new($origin);
} else {
$originUri = Http::createFromString($origin);
}
} catch (\Exception $e) {
throw new HttpException("Invalid origin provided: parsing failed: " . $origin);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ public function isIdempotent(): bool

private function createUriFromString(string $uri): UriInterface
{
if (\method_exists(Uri\Http::class, 'new')) {
return Uri\Http::new($uri);
}

return Uri\Http::createFromString($uri);
}
}
Loading