From bfa7694838927417c5144a4051d04684c4561d6f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 18 Sep 2025 15:17:11 +0200 Subject: [PATCH 1/2] add NoDiscard attribute on mutation free methods --- psalm.xml | 3 +++ src/ClientError.php | 2 ++ src/ConnectionFailed.php | 2 ++ src/Curl.php | 4 ++++ src/Failure.php | 2 ++ src/Information.php | 2 ++ src/MalformedResponse.php | 2 ++ src/MalformedResponse/Raw.php | 3 +++ src/Redirection.php | 2 ++ src/ServerError.php | 2 ++ src/Success.php | 2 ++ src/Transport.php | 1 + 12 files changed, 27 insertions(+) diff --git a/psalm.xml b/psalm.xml index 6b4a878..fa1d427 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,4 +14,7 @@ + + + diff --git a/src/ClientError.php b/src/ClientError.php index 51d1db5..b478923 100644 --- a/src/ClientError.php +++ b/src/ClientError.php @@ -23,11 +23,13 @@ public function __construct(Request $request, Response $response) $this->response = $response; } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function response(): Response { return $this->response; diff --git a/src/ConnectionFailed.php b/src/ConnectionFailed.php index 4b818fe..87ac17e 100644 --- a/src/ConnectionFailed.php +++ b/src/ConnectionFailed.php @@ -13,11 +13,13 @@ public function __construct( ) { } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function reason(): string { return $this->reason; diff --git a/src/Curl.php b/src/Curl.php index a484ee8..c4eda29 100644 --- a/src/Curl.php +++ b/src/Curl.php @@ -79,6 +79,7 @@ public static function of( * * @param positive-int $max */ + #[\NoDiscard] public function maxConcurrency(int $max): self { return new self( @@ -98,6 +99,7 @@ public function maxConcurrency(int $max): self * @param Period $timeout Only seconds are allowed * @param callable(): void $heartbeat */ + #[\NoDiscard] public function heartbeat(Period $timeout, ?callable $heartbeat = null): self { return new self( @@ -120,6 +122,7 @@ public function heartbeat(Period $timeout, ?callable $heartbeat = null): self * * @psalm-mutation-free */ + #[\NoDiscard] public function disableSSLVerification(): self { return new self( @@ -136,6 +139,7 @@ public function disableSSLVerification(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function proxy(Url $proxy): self { return new self( diff --git a/src/Failure.php b/src/Failure.php index 5eb4b3d..704a658 100644 --- a/src/Failure.php +++ b/src/Failure.php @@ -13,11 +13,13 @@ public function __construct( ) { } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function reason(): string { return $this->reason; diff --git a/src/Information.php b/src/Information.php index aaf7777..357f0bd 100644 --- a/src/Information.php +++ b/src/Information.php @@ -23,11 +23,13 @@ public function __construct(Request $request, Response $response) $this->response = $response; } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function response(): Response { return $this->response; diff --git a/src/MalformedResponse.php b/src/MalformedResponse.php index 99945c8..0ec12bd 100644 --- a/src/MalformedResponse.php +++ b/src/MalformedResponse.php @@ -17,11 +17,13 @@ public function __construct(Request $request, ?Raw $raw = null) $this->raw = $raw ?? Raw::none(); } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function raw(): Raw { return $this->raw; diff --git a/src/MalformedResponse/Raw.php b/src/MalformedResponse/Raw.php index d59a768..5908358 100644 --- a/src/MalformedResponse/Raw.php +++ b/src/MalformedResponse/Raw.php @@ -42,6 +42,7 @@ public static function none(): self return new self(Str::of(''), Sequence::of(), Content::none()); } + #[\NoDiscard] public function statusLine(): Str { return $this->statusLine; @@ -50,11 +51,13 @@ public function statusLine(): Str /** * @return Sequence */ + #[\NoDiscard] public function headers(): Sequence { return $this->headers; } + #[\NoDiscard] public function body(): Content { return $this->body; diff --git a/src/Redirection.php b/src/Redirection.php index 91601c7..28b3917 100644 --- a/src/Redirection.php +++ b/src/Redirection.php @@ -23,11 +23,13 @@ public function __construct(Request $request, Response $response) $this->response = $response; } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function response(): Response { return $this->response; diff --git a/src/ServerError.php b/src/ServerError.php index 503345a..5921b71 100644 --- a/src/ServerError.php +++ b/src/ServerError.php @@ -23,11 +23,13 @@ public function __construct(Request $request, Response $response) $this->response = $response; } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function response(): Response { return $this->response; diff --git a/src/Success.php b/src/Success.php index a3fffc5..a6d5506 100644 --- a/src/Success.php +++ b/src/Success.php @@ -23,11 +23,13 @@ public function __construct(Request $request, Response $response) $this->response = $response; } + #[\NoDiscard] public function request(): Request { return $this->request; } + #[\NoDiscard] public function response(): Response { return $this->response; diff --git a/src/Transport.php b/src/Transport.php index 227e16d..5e482fa 100644 --- a/src/Transport.php +++ b/src/Transport.php @@ -14,5 +14,6 @@ interface Transport /** * @return Either */ + #[\NoDiscard] public function __invoke(Request $request): Either; } From 98384ad6bee9b0b480718e94607c9c2170cc74cb Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 18 Sep 2025 15:18:30 +0200 Subject: [PATCH 2/2] flag responses/errors wrappers as immutable --- src/ClientError.php | 3 +++ src/ConnectionFailed.php | 3 +++ src/Failure.php | 3 +++ src/Information.php | 3 +++ src/MalformedResponse.php | 3 +++ src/Redirection.php | 3 +++ src/ServerError.php | 3 +++ src/Success.php | 3 +++ 8 files changed, 24 insertions(+) diff --git a/src/ClientError.php b/src/ClientError.php index b478923..5237fa4 100644 --- a/src/ClientError.php +++ b/src/ClientError.php @@ -8,6 +8,9 @@ Response, }; +/** + * @psalm-immutable + */ final class ClientError { private Request $request; diff --git a/src/ConnectionFailed.php b/src/ConnectionFailed.php index 87ac17e..96d7713 100644 --- a/src/ConnectionFailed.php +++ b/src/ConnectionFailed.php @@ -5,6 +5,9 @@ use Innmind\Http\Request; +/** + * @psalm-immutable + */ final class ConnectionFailed { public function __construct( diff --git a/src/Failure.php b/src/Failure.php index 704a658..d94a710 100644 --- a/src/Failure.php +++ b/src/Failure.php @@ -5,6 +5,9 @@ use Innmind\Http\Request; +/** + * @psalm-immutable + */ final class Failure { public function __construct( diff --git a/src/Information.php b/src/Information.php index 357f0bd..aa7040c 100644 --- a/src/Information.php +++ b/src/Information.php @@ -8,6 +8,9 @@ Response, }; +/** + * @psalm-immutable + */ final class Information { private Request $request; diff --git a/src/MalformedResponse.php b/src/MalformedResponse.php index 0ec12bd..dc5d94d 100644 --- a/src/MalformedResponse.php +++ b/src/MalformedResponse.php @@ -6,6 +6,9 @@ use Innmind\HttpTransport\MalformedResponse\Raw; use Innmind\Http\Request; +/** + * @psalm-immutable + */ final class MalformedResponse { private Request $request; diff --git a/src/Redirection.php b/src/Redirection.php index 28b3917..cc7d357 100644 --- a/src/Redirection.php +++ b/src/Redirection.php @@ -8,6 +8,9 @@ Response, }; +/** + * @psalm-immutable + */ final class Redirection { private Request $request; diff --git a/src/ServerError.php b/src/ServerError.php index 5921b71..f481558 100644 --- a/src/ServerError.php +++ b/src/ServerError.php @@ -8,6 +8,9 @@ Response, }; +/** + * @psalm-immutable + */ final class ServerError { private Request $request; diff --git a/src/Success.php b/src/Success.php index a6d5506..d09bb9d 100644 --- a/src/Success.php +++ b/src/Success.php @@ -8,6 +8,9 @@ Response, }; +/** + * @psalm-immutable + */ final class Success { private Request $request;