From 43c312a4b849c4099e02f29c317f800f8a348468 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 19:26:33 +0100 Subject: [PATCH 1/2] add NoDiscard attributes --- psalm.xml | 3 +++ src/Content/Multipart.php | 4 ++++ src/Factory/CookiesFactory.php | 3 +++ src/Factory/EnvironmentFactory.php | 3 +++ src/Factory/FilesFactory.php | 3 +++ src/Factory/FormFactory.php | 3 +++ src/Factory/HeadersFactory.php | 3 +++ src/Factory/QueryFactory.php | 3 +++ src/Factory/ServerRequestFactory.php | 3 +++ src/Header.php | 4 ++++ src/Header/Accept.php | 2 ++ src/Header/Accept/Charset.php | 3 +++ src/Header/Accept/Encoding.php | 3 +++ src/Header/Accept/Language.php | 3 +++ src/Header/Accept/MediaType.php | 5 +++++ src/Header/AcceptCharset.php | 2 ++ src/Header/AcceptEncoding.php | 2 ++ src/Header/AcceptLanguage.php | 2 ++ src/Header/AcceptRanges.php | 3 +++ src/Header/Age.php | 4 ++++ src/Header/Allow.php | 2 ++ src/Header/Authorization.php | 5 +++++ src/Header/CacheControl.php | 2 ++ src/Header/CacheControl/Directive.php | 1 + src/Header/CacheControl/MaxAge.php | 3 +++ src/Header/CacheControl/MaxStale.php | 3 +++ src/Header/CacheControl/MinimumFresh.php | 3 +++ src/Header/CacheControl/NoCache.php | 3 +++ src/Header/CacheControl/PrivateCache.php | 3 +++ src/Header/CacheControl/SharedMaxAge.php | 3 +++ src/Header/Content/Language.php | 2 ++ src/Header/ContentEncoding.php | 3 +++ src/Header/ContentLanguage.php | 2 ++ src/Header/ContentLength.php | 4 ++++ src/Header/ContentLocation.php | 3 +++ src/Header/ContentRange.php | 7 +++++++ src/Header/ContentType.php | 3 +++ src/Header/ContentType/Boundary.php | 6 ++++++ src/Header/Cookie.php | 3 +++ src/Header/Date.php | 3 +++ src/Header/Expires.php | 3 +++ src/Header/Host.php | 4 ++++ src/Header/IfModifiedSince.php | 3 +++ src/Header/IfUnmodifiedSince.php | 3 +++ src/Header/LastModified.php | 3 +++ src/Header/Link.php | 2 ++ src/Header/Link/Relationship.php | 5 +++++ src/Header/Location.php | 3 +++ src/Header/Parameter.php | 4 ++++ src/Header/Parameter/Quality.php | 3 +++ src/Header/Range.php | 6 ++++++ src/Header/Referrer.php | 3 +++ src/Header/SetCookie.php | 7 +++++++ src/Header/SetCookie/Directive.php | 1 + src/Header/SetCookie/Domain.php | 3 +++ src/Header/SetCookie/Expires.php | 3 +++ src/Header/SetCookie/MaxAge.php | 4 ++++ src/Header/SetCookie/Path.php | 3 +++ src/Header/Value.php | 2 ++ src/Header/WWWAuthenticate.php | 2 ++ src/Header/WWWAuthenticate/Challenge.php | 4 ++++ src/Headers.php | 10 ++++++++++ src/Method.php | 5 +++++ src/ProtocolVersion.php | 2 ++ src/Request.php | 6 ++++++ src/Request/Stringable.php | 2 ++ src/Response.php | 5 +++++ src/Response/Sender.php | 1 + src/Response/Sender/Native.php | 1 + src/Response/StatusCode.php | 11 +++++++++++ src/Response/Stringable.php | 2 ++ src/ServerRequest.php | 11 +++++++++++ src/ServerRequest/Cookies.php | 6 ++++++ src/ServerRequest/Environment.php | 6 ++++++ src/ServerRequest/Files.php | 4 ++++ src/ServerRequest/Form.php | 7 +++++++ src/ServerRequest/Query.php | 7 +++++++ src/ServerRequest/Stringable.php | 2 ++ src/Time/Format/Http.php | 1 + 79 files changed, 285 insertions(+) diff --git a/psalm.xml b/psalm.xml index 510148d8..feccc34e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,4 +14,7 @@ + + + diff --git a/src/Content/Multipart.php b/src/Content/Multipart.php index 18362691..33effc49 100644 --- a/src/Content/Multipart.php +++ b/src/Content/Multipart.php @@ -34,6 +34,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function boundary(Boundary $boundary): self { /** @var Sequence */ @@ -42,6 +43,7 @@ public static function boundary(Boundary $boundary): self return new self($boundary, $parts); } + #[\NoDiscard] public function with(string $name, string $data): self { return new self( @@ -50,6 +52,7 @@ public function with(string $name, string $data): self ); } + #[\NoDiscard] public function withFile(string $name, Binary $file): self { return new self( @@ -58,6 +61,7 @@ public function withFile(string $name, Binary $file): self ); } + #[\NoDiscard] public function asContent(): Content { return Content::ofChunks($this->chunks()); diff --git a/src/Factory/CookiesFactory.php b/src/Factory/CookiesFactory.php index c2ea570f..5b10e1e6 100644 --- a/src/Factory/CookiesFactory.php +++ b/src/Factory/CookiesFactory.php @@ -21,11 +21,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Cookies { return ($this->implementation)(); } + #[\NoDiscard] public static function native(): self { return new self(Native::new()); @@ -36,6 +38,7 @@ public static function native(): self * * @param pure-Closure(): Cookies $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/EnvironmentFactory.php b/src/Factory/EnvironmentFactory.php index aee5dcea..9f417e7c 100644 --- a/src/Factory/EnvironmentFactory.php +++ b/src/Factory/EnvironmentFactory.php @@ -21,11 +21,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Environment { return ($this->implementation)(); } + #[\NoDiscard] public static function native(): self { return new self(Native::new()); @@ -36,6 +38,7 @@ public static function native(): self * * @param pure-Closure(): Environment $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/FilesFactory.php b/src/Factory/FilesFactory.php index 5a4a61d1..ad1f13e6 100644 --- a/src/Factory/FilesFactory.php +++ b/src/Factory/FilesFactory.php @@ -22,11 +22,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Files { return ($this->implementation)(); } + #[\NoDiscard] public static function native(IO $io): self { return new self(Native::new($io)); @@ -37,6 +39,7 @@ public static function native(IO $io): self * * @param pure-Closure(): Files $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/FormFactory.php b/src/Factory/FormFactory.php index 55022f0e..53e90be3 100644 --- a/src/Factory/FormFactory.php +++ b/src/Factory/FormFactory.php @@ -21,11 +21,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Form { return ($this->implementation)(); } + #[\NoDiscard] public static function native(): self { return new self(Native::new()); @@ -36,6 +38,7 @@ public static function native(): self * * @param pure-Closure(): Form $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/HeadersFactory.php b/src/Factory/HeadersFactory.php index 20684443..3a965af0 100644 --- a/src/Factory/HeadersFactory.php +++ b/src/Factory/HeadersFactory.php @@ -22,11 +22,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Headers { return ($this->implementation)(); } + #[\NoDiscard] public static function native(Clock $clock): self { return new self(Native::new($clock)); @@ -37,6 +39,7 @@ public static function native(Clock $clock): self * * @param pure-Closure(): Headers $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/QueryFactory.php b/src/Factory/QueryFactory.php index 61ed1bd5..3c54b6de 100644 --- a/src/Factory/QueryFactory.php +++ b/src/Factory/QueryFactory.php @@ -21,11 +21,13 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): Query { return ($this->implementation)(); } + #[\NoDiscard] public static function native(): self { return new self(Native::new()); @@ -36,6 +38,7 @@ public static function native(): self * * @param pure-Closure(): Query $factory */ + #[\NoDiscard] public static function of(\Closure $factory): self { return new self($factory); diff --git a/src/Factory/ServerRequestFactory.php b/src/Factory/ServerRequestFactory.php index 7fb75a38..7cb41ff5 100644 --- a/src/Factory/ServerRequestFactory.php +++ b/src/Factory/ServerRequestFactory.php @@ -39,6 +39,7 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(): ServerRequest { /** @psalm-suppress MixedArgument */ @@ -94,6 +95,7 @@ public function __invoke(): ServerRequest /** * Return a fully configured factory */ + #[\NoDiscard] public static function native( Clock $clock, ?IO $io = null, @@ -125,6 +127,7 @@ public static function native( * @param \Closure(): Content $bodyFactory * @param array $server */ + #[\NoDiscard] public static function of( HeadersFactory $headersFactory, \Closure $bodyFactory, diff --git a/src/Header.php b/src/Header.php index c594eb64..3d4e7ccd 100644 --- a/src/Header.php +++ b/src/Header.php @@ -27,11 +27,13 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(string $name, Value ...$values): self { return new self($name, Sequence::of(...$values)); } + #[\NoDiscard] public function name(): string { return $this->name; @@ -40,11 +42,13 @@ public function name(): string /** * @return Sequence */ + #[\NoDiscard] public function values(): Sequence { return $this->values; } + #[\NoDiscard] public function toString(): string { $values = $this->values->map(static fn($value) => $value->toString()); diff --git a/src/Header/Accept.php b/src/Header/Accept.php index eee0eaf9..9de079af 100644 --- a/src/Header/Accept.php +++ b/src/Header/Accept.php @@ -25,12 +25,14 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(MediaType $first, MediaType ...$values): self { return new self(Sequence::of($first, ...$values)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Accept/Charset.php b/src/Header/Accept/Charset.php index 324484d2..516852cf 100644 --- a/src/Header/Accept/Charset.php +++ b/src/Header/Accept/Charset.php @@ -25,6 +25,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $charset, ?Quality $quality = null): Maybe { $charset = Str::of($charset); @@ -40,11 +41,13 @@ public static function maybe(string $charset, ?Quality $quality = null): Maybe return Maybe::just(new self($charset, $quality ?? Quality::max())); } + #[\NoDiscard] public function quality(): Quality { return $this->quality; } + #[\NoDiscard] public function toString(): string { return $this diff --git a/src/Header/Accept/Encoding.php b/src/Header/Accept/Encoding.php index bb0e085c..e44be739 100644 --- a/src/Header/Accept/Encoding.php +++ b/src/Header/Accept/Encoding.php @@ -25,6 +25,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $coding, ?Quality $quality = null): Maybe { $coding = Str::of($coding); @@ -40,11 +41,13 @@ public static function maybe(string $coding, ?Quality $quality = null): Maybe return Maybe::just(new self($coding, $quality ?? Quality::max())); } + #[\NoDiscard] public function quality(): Quality { return $this->quality; } + #[\NoDiscard] public function toString(): string { return $this diff --git a/src/Header/Accept/Language.php b/src/Header/Accept/Language.php index 3c3aed0e..03a73887 100644 --- a/src/Header/Accept/Language.php +++ b/src/Header/Accept/Language.php @@ -25,6 +25,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $language, ?Quality $quality = null): Maybe { $language = Str::of($language); @@ -40,11 +41,13 @@ public static function maybe(string $language, ?Quality $quality = null): Maybe return Maybe::just(new self($language, $quality ?? Quality::max())); } + #[\NoDiscard] public function quality(): Quality { return $this->quality; } + #[\NoDiscard] public function toString(): string { return $this diff --git a/src/Header/Accept/MediaType.php b/src/Header/Accept/MediaType.php index 82c701f7..f93767ab 100644 --- a/src/Header/Accept/MediaType.php +++ b/src/Header/Accept/MediaType.php @@ -28,6 +28,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe( string $type, string $subType, @@ -57,11 +58,13 @@ public static function maybe( return Maybe::just(new self($type, $subType, $map)); } + #[\NoDiscard] public function type(): string { return $this->type; } + #[\NoDiscard] public function subType(): string { return $this->subType; @@ -70,11 +73,13 @@ public function subType(): string /** * @return Map */ + #[\NoDiscard] public function parameters(): Map { return $this->parameters; } + #[\NoDiscard] public function toString(): string { $parameters = $this->parameters->values()->map( diff --git a/src/Header/AcceptCharset.php b/src/Header/AcceptCharset.php index f5ffa965..f7ef6cb4 100644 --- a/src/Header/AcceptCharset.php +++ b/src/Header/AcceptCharset.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Charset ...$charsets): self { return new self(Sequence::of(...$charsets)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/AcceptEncoding.php b/src/Header/AcceptEncoding.php index bf102f98..7b8c6e39 100644 --- a/src/Header/AcceptEncoding.php +++ b/src/Header/AcceptEncoding.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Encoding ...$encodings): self { return new self(Sequence::of(...$encodings)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/AcceptLanguage.php b/src/Header/AcceptLanguage.php index 96f2bcfe..ded5f0cf 100644 --- a/src/Header/AcceptLanguage.php +++ b/src/Header/AcceptLanguage.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Language ...$languages): self { return new self(Sequence::of(...$languages)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/AcceptRanges.php b/src/Header/AcceptRanges.php index 80123d41..b125edff 100644 --- a/src/Header/AcceptRanges.php +++ b/src/Header/AcceptRanges.php @@ -27,6 +27,7 @@ private function __construct( * * @throws DomainException */ + #[\NoDiscard] public static function of(string $range): self { return self::maybe($range)->match( @@ -40,6 +41,7 @@ public static function of(string $range): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $range): Maybe { return Maybe::just($range) @@ -49,6 +51,7 @@ public static function maybe(string $range): Maybe } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Age.php b/src/Header/Age.php index 6a817739..f3d21470 100644 --- a/src/Header/Age.php +++ b/src/Header/Age.php @@ -24,6 +24,7 @@ private function __construct( * * @param int<0, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -34,6 +35,7 @@ public static function of(int $age): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(int $age): Maybe { return Maybe::of(match (true) { @@ -45,12 +47,14 @@ public static function maybe(int $age): Maybe /** * @return int<0, max> */ + #[\NoDiscard] public function age(): int { return $this->age; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of('Age', Value::of((string) $this->age)); diff --git a/src/Header/Allow.php b/src/Header/Allow.php index 3e177bdf..82ed9f35 100644 --- a/src/Header/Allow.php +++ b/src/Header/Allow.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Method ...$methods): self { return new self(Sequence::of(...$methods)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Authorization.php b/src/Header/Authorization.php index f84996c0..2726bd49 100644 --- a/src/Header/Authorization.php +++ b/src/Header/Authorization.php @@ -26,6 +26,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(string $scheme, string $parameter): self { return self::maybe($scheme, $parameter)->match( @@ -39,6 +40,7 @@ public static function of(string $scheme, string $parameter): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $scheme, string $parameter): Maybe { return Maybe::just($scheme) @@ -47,17 +49,20 @@ public static function maybe(string $scheme, string $parameter): Maybe ->map(static fn() => new self($scheme, $parameter)); } + #[\NoDiscard] public function scheme(): string { return $this->scheme; } + #[\NoDiscard] public function parameter(): string { return $this->parameter; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/CacheControl.php b/src/Header/CacheControl.php index 02a91838..7e892a64 100644 --- a/src/Header/CacheControl.php +++ b/src/Header/CacheControl.php @@ -32,6 +32,7 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of( Directive|MaxAge|MaxStale|MinimumFresh|NoCache|PrivateCache|SharedMaxAge $first, Directive|MaxAge|MaxStale|MinimumFresh|NoCache|PrivateCache|SharedMaxAge ...$values, @@ -40,6 +41,7 @@ public static function of( } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/CacheControl/Directive.php b/src/Header/CacheControl/Directive.php index 604f7927..3cc99e13 100644 --- a/src/Header/CacheControl/Directive.php +++ b/src/Header/CacheControl/Directive.php @@ -17,6 +17,7 @@ enum Directive case proxyRevalidate; case public; + #[\NoDiscard] public function toString(): string { return match ($this) { diff --git a/src/Header/CacheControl/MaxAge.php b/src/Header/CacheControl/MaxAge.php index 13840e5c..8d52fe80 100644 --- a/src/Header/CacheControl/MaxAge.php +++ b/src/Header/CacheControl/MaxAge.php @@ -21,6 +21,7 @@ private function __construct( * * @param int<0, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -29,11 +30,13 @@ public static function of(int $age): self /** * @return int<0, max> */ + #[\NoDiscard] public function age(): int { return $this->age; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/CacheControl/MaxStale.php b/src/Header/CacheControl/MaxStale.php index 021a2e35..860a54ed 100644 --- a/src/Header/CacheControl/MaxStale.php +++ b/src/Header/CacheControl/MaxStale.php @@ -21,6 +21,7 @@ private function __construct( * * @param int<0, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -29,11 +30,13 @@ public static function of(int $age): self /** * @return int<0, max> */ + #[\NoDiscard] public function age(): int { return $this->age; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/CacheControl/MinimumFresh.php b/src/Header/CacheControl/MinimumFresh.php index 42bc3b3d..a6be4612 100644 --- a/src/Header/CacheControl/MinimumFresh.php +++ b/src/Header/CacheControl/MinimumFresh.php @@ -21,6 +21,7 @@ private function __construct( * * @param int<0, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -29,11 +30,13 @@ public static function of(int $age): self /** * @return int<0, max> */ + #[\NoDiscard] public function age(): int { return $this->age; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/CacheControl/NoCache.php b/src/Header/CacheControl/NoCache.php index 8936cb55..b0b9e9db 100644 --- a/src/Header/CacheControl/NoCache.php +++ b/src/Header/CacheControl/NoCache.php @@ -23,6 +23,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $field): Maybe { if (!Str::of($field)->matches('~^\w*$~')) { @@ -33,11 +34,13 @@ public static function maybe(string $field): Maybe return Maybe::just(new self($field)); } + #[\NoDiscard] public function field(): string { return $this->field; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/CacheControl/PrivateCache.php b/src/Header/CacheControl/PrivateCache.php index 3d1a125c..5bec07a9 100644 --- a/src/Header/CacheControl/PrivateCache.php +++ b/src/Header/CacheControl/PrivateCache.php @@ -23,6 +23,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $field): Maybe { if (!Str::of($field)->matches('~^\w*$~')) { @@ -33,11 +34,13 @@ public static function maybe(string $field): Maybe return Maybe::just(new self($field)); } + #[\NoDiscard] public function field(): string { return $this->field; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/CacheControl/SharedMaxAge.php b/src/Header/CacheControl/SharedMaxAge.php index d1320182..95eefab1 100644 --- a/src/Header/CacheControl/SharedMaxAge.php +++ b/src/Header/CacheControl/SharedMaxAge.php @@ -21,6 +21,7 @@ private function __construct( * * @param int<0, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -29,11 +30,13 @@ public static function of(int $age): self /** * @return int<0, max> */ + #[\NoDiscard] public function age(): int { return $this->age; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/Content/Language.php b/src/Header/Content/Language.php index 60eb17b9..34757197 100644 --- a/src/Header/Content/Language.php +++ b/src/Header/Content/Language.php @@ -23,6 +23,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $language): Maybe { if (!Str::of($language)->matches('~^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$~')) { @@ -33,6 +34,7 @@ public static function maybe(string $language): Maybe return Maybe::just(new self($language)); } + #[\NoDiscard] public function toString(): string { return $this->language; diff --git a/src/Header/ContentEncoding.php b/src/Header/ContentEncoding.php index 8adbf853..8053cf20 100644 --- a/src/Header/ContentEncoding.php +++ b/src/Header/ContentEncoding.php @@ -27,6 +27,7 @@ private function __construct( * * @throws DomainException */ + #[\NoDiscard] public static function of(string $encoding): self { return self::maybe($encoding)->match( @@ -40,6 +41,7 @@ public static function of(string $encoding): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $encoding): Maybe { return Maybe::just($encoding) @@ -49,6 +51,7 @@ public static function maybe(string $encoding): Maybe } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/ContentLanguage.php b/src/Header/ContentLanguage.php index 75cd28a7..42816259 100644 --- a/src/Header/ContentLanguage.php +++ b/src/Header/ContentLanguage.php @@ -26,12 +26,14 @@ private function __construct( * @no-named-arguments * @psalm-pure */ + #[\NoDiscard] public static function of(Language ...$languages): self { return new self(Sequence::of(...$languages)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/ContentLength.php b/src/Header/ContentLength.php index 131bc460..1e09474b 100644 --- a/src/Header/ContentLength.php +++ b/src/Header/ContentLength.php @@ -24,6 +24,7 @@ private function __construct( * * @param int<0, max> $length */ + #[\NoDiscard] public static function of(int $length): self { return new self($length); @@ -34,6 +35,7 @@ public static function of(int $length): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(int $length): Maybe { return Maybe::of(match (true) { @@ -45,12 +47,14 @@ public static function maybe(int $length): Maybe /** * @return int<0, max> */ + #[\NoDiscard] public function length(): int { return $this->length; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/ContentLocation.php b/src/Header/ContentLocation.php index a4f65c59..fa17b954 100644 --- a/src/Header/ContentLocation.php +++ b/src/Header/ContentLocation.php @@ -19,17 +19,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Url $location): self { return new self($location); } + #[\NoDiscard] public function url(): Url { return $this->url; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/ContentRange.php b/src/Header/ContentRange.php index a4a2b681..c1c9b6d1 100644 --- a/src/Header/ContentRange.php +++ b/src/Header/ContentRange.php @@ -33,6 +33,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of( string $unit, int $firstPosition, @@ -50,6 +51,7 @@ public static function of( * * @return Maybe */ + #[\NoDiscard] public static function maybe( string $unit, int $firstPosition, @@ -76,6 +78,7 @@ public static function maybe( )); } + #[\NoDiscard] public function unit(): string { return $this->unit; @@ -84,6 +87,7 @@ public function unit(): string /** * @return int<0, max> */ + #[\NoDiscard] public function firstPosition(): int { return $this->firstPosition; @@ -92,6 +96,7 @@ public function firstPosition(): int /** * @return int<0, max> */ + #[\NoDiscard] public function lastPosition(): int { return $this->lastPosition; @@ -100,12 +105,14 @@ public function lastPosition(): int /** * @return Maybe> */ + #[\NoDiscard] public function length(): Maybe { return Maybe::of($this->length); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/ContentType.php b/src/Header/ContentType.php index fef87233..dda090c3 100644 --- a/src/Header/ContentType.php +++ b/src/Header/ContentType.php @@ -20,17 +20,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(MediaType $content): self { return new self($content); } + #[\NoDiscard] public function content(): MediaType { return $this->content; } #[\Override] + #[\NoDiscard] public function normalize(): Header { $mediaType = MediaType::from( diff --git a/src/Header/ContentType/Boundary.php b/src/Header/ContentType/Boundary.php index d23db904..331f3321 100644 --- a/src/Header/ContentType/Boundary.php +++ b/src/Header/ContentType/Boundary.php @@ -32,6 +32,7 @@ private function __construct( * * @throws DomainException */ + #[\NoDiscard] public static function of(string $value): self { return self::maybe($value)->match( @@ -45,6 +46,7 @@ public static function of(string $value): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $value): Maybe { return Str::of($value) @@ -55,16 +57,19 @@ public static function maybe(string $value): Maybe ->map(static fn($value) => new self($value->toString())); } + #[\NoDiscard] public static function uuid(): self { return self::of(Uuid::uuid4()->toString()); } + #[\NoDiscard] public function value(): string { return $this->value; } + #[\NoDiscard] public function toHeader(): ContentType { return ContentType::of(MediaType\MediaType::from( @@ -78,6 +83,7 @@ public function toHeader(): ContentType )); } + #[\NoDiscard] public function toParameter(): Parameter { return Parameter::of('boundary', $this->value); diff --git a/src/Header/Cookie.php b/src/Header/Cookie.php index f42e43d4..2bd2d548 100644 --- a/src/Header/Cookie.php +++ b/src/Header/Cookie.php @@ -26,6 +26,7 @@ private function __construct( * @no-named-arguments * @psalm-pure */ + #[\NoDiscard] public static function of(Parameter ...$parameters): self { /** @var Map */ @@ -44,12 +45,14 @@ public static function of(Parameter ...$parameters): self /** * @return Map */ + #[\NoDiscard] public function parameters(): Map { return $this->parameters; } #[\Override] + #[\NoDiscard] public function normalize(): Header { $parameters = $this->parameters->values()->map( diff --git a/src/Header/Date.php b/src/Header/Date.php index f7664f95..c8efbbcc 100644 --- a/src/Header/Date.php +++ b/src/Header/Date.php @@ -25,17 +25,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Point $point): self { return new self($point); } + #[\NoDiscard] public function date(): Point { return $this->point; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Expires.php b/src/Header/Expires.php index 2dc62fd1..6ef558ea 100644 --- a/src/Header/Expires.php +++ b/src/Header/Expires.php @@ -25,17 +25,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Point $point): self { return new self($point); } + #[\NoDiscard] public function date(): Point { return $this->point; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Host.php b/src/Header/Host.php index 740216e1..a002ef6c 100644 --- a/src/Header/Host.php +++ b/src/Header/Host.php @@ -23,22 +23,26 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(UrlHost $host, Port $port): self { return new self($host, $port); } + #[\NoDiscard] public function host(): UrlHost { return $this->host; } + #[\NoDiscard] public function port(): Port { return $this->port; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/IfModifiedSince.php b/src/Header/IfModifiedSince.php index 19cc8226..6ca7c84d 100644 --- a/src/Header/IfModifiedSince.php +++ b/src/Header/IfModifiedSince.php @@ -25,17 +25,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Point $point): self { return new self($point); } + #[\NoDiscard] public function date(): Point { return $this->point; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/IfUnmodifiedSince.php b/src/Header/IfUnmodifiedSince.php index 3110fd8d..a61d03be 100644 --- a/src/Header/IfUnmodifiedSince.php +++ b/src/Header/IfUnmodifiedSince.php @@ -25,17 +25,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Point $point): self { return new self($point); } + #[\NoDiscard] public function date(): Point { return $this->point; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/LastModified.php b/src/Header/LastModified.php index 81d49edd..526fe45d 100644 --- a/src/Header/LastModified.php +++ b/src/Header/LastModified.php @@ -25,17 +25,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Point $point): self { return new self($point); } + #[\NoDiscard] public function date(): Point { return $this->point; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Link.php b/src/Header/Link.php index 0de9a5ae..73ee6cf2 100644 --- a/src/Header/Link.php +++ b/src/Header/Link.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Relationship ...$relationships): self { return new self(Sequence::of(...$relationships)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Link/Relationship.php b/src/Header/Link/Relationship.php index a5bda622..20cb84bf 100644 --- a/src/Header/Link/Relationship.php +++ b/src/Header/Link/Relationship.php @@ -31,6 +31,7 @@ private function __construct( * * @param ?non-empty-string $rel */ + #[\NoDiscard] public static function of( Url $url, ?string $rel = null, @@ -49,11 +50,13 @@ public static function of( return new self($url, $rel ?? 'related', $map); } + #[\NoDiscard] public function url(): Url { return $this->url; } + #[\NoDiscard] public function kind(): string { return $this->rel; @@ -62,11 +65,13 @@ public function kind(): string /** * @return Map */ + #[\NoDiscard] public function parameters(): Map { return $this->parameters; } + #[\NoDiscard] public function toString(): string { $parameters = $this->parameters->values()->map( diff --git a/src/Header/Location.php b/src/Header/Location.php index c4ff2d7f..e2cdc2b2 100644 --- a/src/Header/Location.php +++ b/src/Header/Location.php @@ -19,17 +19,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Url $location): self { return new self($location); } + #[\NoDiscard] public function url(): Url { return $this->location; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Parameter.php b/src/Header/Parameter.php index ce9adb6f..c5247c3c 100644 --- a/src/Header/Parameter.php +++ b/src/Header/Parameter.php @@ -31,21 +31,25 @@ private function __construct(string $name, string $value) /** * @psalm-pure */ + #[\NoDiscard] public static function of(string $name, string $value): self { return new self($name, $value); } + #[\NoDiscard] public function name(): string { return $this->name; } + #[\NoDiscard] public function value(): string { return $this->value; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Header/Parameter/Quality.php b/src/Header/Parameter/Quality.php index 33c6ae55..df022953 100644 --- a/src/Header/Parameter/Quality.php +++ b/src/Header/Parameter/Quality.php @@ -24,6 +24,7 @@ private function __construct( * * @param int<0, 100> $percent */ + #[\NoDiscard] public static function of(int $percent): self { return new self($percent); @@ -32,11 +33,13 @@ public static function of(int $percent): self /** * @psalm-pure */ + #[\NoDiscard] public static function max(): self { return new self(100); } + #[\NoDiscard] public function toParameter(): Parameter { $value = Str::of(\sprintf( diff --git a/src/Header/Range.php b/src/Header/Range.php index 14041dfd..a7a5b500 100644 --- a/src/Header/Range.php +++ b/src/Header/Range.php @@ -33,6 +33,7 @@ private function __construct( * * @throws DomainException */ + #[\NoDiscard] public static function of( string $unit, int $firstPosition, @@ -49,6 +50,7 @@ public static function of( * * @return Maybe */ + #[\NoDiscard] public static function maybe( string $unit, int $firstPosition, @@ -67,6 +69,7 @@ public static function maybe( return Maybe::just(new self($unit, $firstPosition, $lastPosition)); } + #[\NoDiscard] public function unit(): string { return $this->unit; @@ -75,6 +78,7 @@ public function unit(): string /** * @return int<0, max> */ + #[\NoDiscard] public function firstPosition(): int { return $this->firstPosition; @@ -83,12 +87,14 @@ public function firstPosition(): int /** * @return int<0, max> */ + #[\NoDiscard] public function lastPosition(): int { return $this->lastPosition; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/Referrer.php b/src/Header/Referrer.php index 207f0259..49037ced 100644 --- a/src/Header/Referrer.php +++ b/src/Header/Referrer.php @@ -19,17 +19,20 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Url $referrer): self { return new self($referrer); } + #[\NoDiscard] public function referrer(): Url { return $this->referrer; } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/SetCookie.php b/src/Header/SetCookie.php index fd7397f1..6fdc62bc 100644 --- a/src/Header/SetCookie.php +++ b/src/Header/SetCookie.php @@ -36,6 +36,7 @@ private function __construct( * @no-named-arguments * @psalm-pure */ + #[\NoDiscard] public static function of( string $name, string $value, @@ -48,6 +49,7 @@ public static function of( ); } + #[\NoDiscard] public function and(self $cookie): self { return new self( @@ -57,11 +59,13 @@ public function and(self $cookie): self ); } + #[\NoDiscard] public function name(): string { return $this->value->name(); } + #[\NoDiscard] public function value(): string { return $this->value->value(); @@ -70,6 +74,7 @@ public function value(): string /** * @return Sequence */ + #[\NoDiscard] public function parameters(): Sequence { return $this->parameters; @@ -78,12 +83,14 @@ public function parameters(): Sequence /** * @return Sequence */ + #[\NoDiscard] public function cookies(): Sequence { return Sequence::of($this)->append($this->others); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/SetCookie/Directive.php b/src/Header/SetCookie/Directive.php index 84fa5e2f..a0cfb86b 100644 --- a/src/Header/SetCookie/Directive.php +++ b/src/Header/SetCookie/Directive.php @@ -15,6 +15,7 @@ enum Directive case secure; case httpOnly; + #[\NoDiscard] public function toParameter(): Parameter { return match ($this) { diff --git a/src/Header/SetCookie/Domain.php b/src/Header/SetCookie/Domain.php index 8516a9cb..ea1cd2af 100644 --- a/src/Header/SetCookie/Domain.php +++ b/src/Header/SetCookie/Domain.php @@ -19,16 +19,19 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(Host $host): self { return new self($host); } + #[\NoDiscard] public function host(): Host { return $this->host; } + #[\NoDiscard] public function toParameter(): Parameter { return Parameter::of('Domain', $this->host->toString()); diff --git a/src/Header/SetCookie/Expires.php b/src/Header/SetCookie/Expires.php index 93d67878..2840577b 100644 --- a/src/Header/SetCookie/Expires.php +++ b/src/Header/SetCookie/Expires.php @@ -25,16 +25,19 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function at(Point $date): self { return new self($date->changeOffset(Offset::utc())); } + #[\NoDiscard] public function date(): Point { return $this->date; } + #[\NoDiscard] public function toParameter(): Parameter { return Parameter::of( diff --git a/src/Header/SetCookie/MaxAge.php b/src/Header/SetCookie/MaxAge.php index bf1af28f..5b11fc0a 100644 --- a/src/Header/SetCookie/MaxAge.php +++ b/src/Header/SetCookie/MaxAge.php @@ -23,6 +23,7 @@ private function __construct( * * @param int<1, max> $age */ + #[\NoDiscard] public static function of(int $age): self { return new self($age); @@ -31,11 +32,13 @@ public static function of(int $age): self /** * @psalm-pure */ + #[\NoDiscard] public static function expire(): self { return new self(null); } + #[\NoDiscard] public function toInt(): int { return match ($this->age) { @@ -44,6 +47,7 @@ public function toInt(): int }; } + #[\NoDiscard] public function toParameter(): Parameter { return Parameter::of('Max-Age', (string) $this->toInt()); diff --git a/src/Header/SetCookie/Path.php b/src/Header/SetCookie/Path.php index b5eabb93..4f198d83 100644 --- a/src/Header/SetCookie/Path.php +++ b/src/Header/SetCookie/Path.php @@ -19,16 +19,19 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(UrlPath $path): self { return new self($path); } + #[\NoDiscard] public function path(): UrlPath { return $this->path; } + #[\NoDiscard] public function toParameter(): Parameter { return Parameter::of('Path', $this->path->toString()); diff --git a/src/Header/Value.php b/src/Header/Value.php index 13f98323..d46ce5bf 100644 --- a/src/Header/Value.php +++ b/src/Header/Value.php @@ -16,11 +16,13 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(string $value): self { return new self($value); } + #[\NoDiscard] public function toString(): string { return $this->value; diff --git a/src/Header/WWWAuthenticate.php b/src/Header/WWWAuthenticate.php index c688cd2f..79fa82f0 100644 --- a/src/Header/WWWAuthenticate.php +++ b/src/Header/WWWAuthenticate.php @@ -26,12 +26,14 @@ private function __construct( * @psalm-pure * @no-named-arguments */ + #[\NoDiscard] public static function of(Challenge ...$challenges): self { return new self(Sequence::of(...$challenges)); } #[\Override] + #[\NoDiscard] public function normalize(): Header { return Header::of( diff --git a/src/Header/WWWAuthenticate/Challenge.php b/src/Header/WWWAuthenticate/Challenge.php index 991dd59e..ced0bb89 100644 --- a/src/Header/WWWAuthenticate/Challenge.php +++ b/src/Header/WWWAuthenticate/Challenge.php @@ -25,6 +25,7 @@ private function __construct( * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $scheme, string $realm): Maybe { $scheme = Str::of($scheme); @@ -37,16 +38,19 @@ public static function maybe(string $scheme, string $realm): Maybe return Maybe::just(new self($scheme->toString(), $realm)); } + #[\NoDiscard] public function scheme(): string { return $this->scheme; } + #[\NoDiscard] public function realm(): string { return $this->realm; } + #[\NoDiscard] public function toString(): string { return Str::of($this->scheme) diff --git a/src/Headers.php b/src/Headers.php index fe202991..65c8424c 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -25,6 +25,7 @@ private function __construct( ) { } + #[\NoDiscard] public function __invoke(Header|Header\Custom $header): self { $name = self::normalize(match (true) { @@ -39,6 +40,7 @@ public function __invoke(Header|Header\Custom $header): self * @no-named-arguments * @psalm-pure */ + #[\NoDiscard] public static function of(Header|Header\Custom ...$headers): self { return Sequence::of(...$headers)->reduce( @@ -52,6 +54,7 @@ public static function of(Header|Header\Custom ...$headers): self * * @return Maybe
*/ + #[\NoDiscard] public function get(string $name): Maybe { $normalized = self::normalize($name); @@ -72,6 +75,7 @@ public function get(string $name): Maybe * * @return Maybe */ + #[\NoDiscard] public function find(string $type): Maybe { return $this @@ -86,6 +90,7 @@ public function find(string $type): Maybe * * @param string $name Case insensitive */ + #[\NoDiscard] public function contains(string $name): bool { return $this->get($name)->match( @@ -97,6 +102,7 @@ public function contains(string $name): bool /** * @param callable(Header): bool $filter */ + #[\NoDiscard] public function filter(callable $filter): self { return new self($this->headers->filter(static fn($_, $header) => match (true) { @@ -108,6 +114,7 @@ public function filter(callable $filter): self /** * @param callable(Header|Header\Custom): void $function */ + #[\NoDiscard] public function foreach(callable $function): SideEffect { return $this->headers->values()->foreach($function); @@ -121,12 +128,14 @@ public function foreach(callable $function): SideEffect * * @return R */ + #[\NoDiscard] public function reduce($carry, callable $reducer) { return $this->all()->reduce($carry, $reducer); } #[\Override] + #[\NoDiscard] public function count(): int { return $this->headers->size(); @@ -135,6 +144,7 @@ public function count(): int /** * @return Sequence
*/ + #[\NoDiscard] public function all(): Sequence { return $this->headers->values()->map(static fn($header) => match (true) { diff --git a/src/Method.php b/src/Method.php index 6a2d66d0..9746585b 100644 --- a/src/Method.php +++ b/src/Method.php @@ -26,6 +26,7 @@ enum Method * @psalm-pure * @throws \UnhandledMatchError */ + #[\NoDiscard] public static function of(string $method): self { return match ($method) { @@ -48,6 +49,7 @@ public static function of(string $method): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $method): Maybe { try { @@ -58,6 +60,7 @@ public static function maybe(string $method): Maybe } } + #[\NoDiscard] public function safe(): bool { return match ($this) { @@ -75,6 +78,7 @@ public function safe(): bool }; } + #[\NoDiscard] public function idempotent(): bool { return match ($this) { @@ -92,6 +96,7 @@ public function idempotent(): bool }; } + #[\NoDiscard] public function toString(): string { return match ($this) { diff --git a/src/ProtocolVersion.php b/src/ProtocolVersion.php index 3e6cad02..17caa18e 100644 --- a/src/ProtocolVersion.php +++ b/src/ProtocolVersion.php @@ -19,6 +19,7 @@ enum ProtocolVersion * * @return Maybe */ + #[\NoDiscard] public static function maybe(int $major, int $minor): Maybe { /** @var Maybe */ @@ -33,6 +34,7 @@ public static function maybe(int $major, int $minor): Maybe /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return match ($this) { diff --git a/src/Request.php b/src/Request.php index 877e5010..6ea4e0f6 100644 --- a/src/Request.php +++ b/src/Request.php @@ -23,6 +23,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of( Url $url, Method $method, @@ -39,26 +40,31 @@ public static function of( ); } + #[\NoDiscard] public function url(): Url { return $this->url; } + #[\NoDiscard] public function method(): Method { return $this->method; } + #[\NoDiscard] public function protocolVersion(): ProtocolVersion { return $this->protocolVersion; } + #[\NoDiscard] public function headers(): Headers { return $this->headers; } + #[\NoDiscard] public function body(): Content { return $this->body; diff --git a/src/Request/Stringable.php b/src/Request/Stringable.php index 520c66b7..04592e95 100644 --- a/src/Request/Stringable.php +++ b/src/Request/Stringable.php @@ -19,6 +19,7 @@ private function __construct() { } + #[\NoDiscard] public function __invoke(Request $request): Content { $status = Str::of("%s %s HTTP/%s\n")->sprintf( @@ -48,6 +49,7 @@ public function __invoke(Request $request): Content /** * @psalm-pure */ + #[\NoDiscard] public static function new(): self { return new self; diff --git a/src/Response.php b/src/Response.php index 432d6c67..5d461f0b 100644 --- a/src/Response.php +++ b/src/Response.php @@ -22,6 +22,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of( StatusCode $statusCode, ProtocolVersion $protocolVersion, @@ -36,21 +37,25 @@ public static function of( ); } + #[\NoDiscard] public function protocolVersion(): ProtocolVersion { return $this->protocolVersion; } + #[\NoDiscard] public function headers(): Headers { return $this->headers; } + #[\NoDiscard] public function body(): Content { return $this->body; } + #[\NoDiscard] public function statusCode(): StatusCode { return $this->statusCode; diff --git a/src/Response/Sender.php b/src/Response/Sender.php index ded01009..a8f6dc0d 100644 --- a/src/Response/Sender.php +++ b/src/Response/Sender.php @@ -14,5 +14,6 @@ interface Sender /** * @return Attempt */ + #[\NoDiscard] public function __invoke(Response $response): Attempt; } diff --git a/src/Response/Sender/Native.php b/src/Response/Sender/Native.php index 77404969..16a5f63d 100644 --- a/src/Response/Sender/Native.php +++ b/src/Response/Sender/Native.php @@ -82,6 +82,7 @@ public function __invoke(Response $response): Attempt return Attempt::result(SideEffect::identity()); } + #[\NoDiscard] public static function of(Clock $clock): self { return new self($clock); diff --git a/src/Response/StatusCode.php b/src/Response/StatusCode.php index 42959778..2395dc2b 100644 --- a/src/Response/StatusCode.php +++ b/src/Response/StatusCode.php @@ -90,6 +90,7 @@ enum StatusCode: int * * @throws \UnhandledMatchError */ + #[\NoDiscard] public static function of(int $code): self { return match ($code) { @@ -175,6 +176,7 @@ public static function of(int $code): self * * @return Maybe */ + #[\NoDiscard] public static function maybe(int $code): Maybe { try { @@ -185,6 +187,7 @@ public static function maybe(int $code): Maybe } } + #[\NoDiscard] public function toInt(): int { return $this->value; @@ -193,11 +196,13 @@ public function toInt(): int /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return (string) $this->toInt(); } + #[\NoDiscard] public function range(): StatusCode\Range { return match ($this) { @@ -278,26 +283,31 @@ public function range(): StatusCode\Range }; } + #[\NoDiscard] public function informational(): bool { return $this->range() === StatusCode\Range::informational; } + #[\NoDiscard] public function successful(): bool { return $this->range() === StatusCode\Range::successful; } + #[\NoDiscard] public function redirection(): bool { return $this->range() === StatusCode\Range::redirection; } + #[\NoDiscard] public function clientError(): bool { return $this->range() === StatusCode\Range::clientError; } + #[\NoDiscard] public function serverError(): bool { return $this->range() === StatusCode\Range::serverError; @@ -306,6 +316,7 @@ public function serverError(): bool /** * @return non-empty-string */ + #[\NoDiscard] public function reasonPhrase(): string { return match ($this) { diff --git a/src/Response/Stringable.php b/src/Response/Stringable.php index 8c09f281..89a3b2a4 100644 --- a/src/Response/Stringable.php +++ b/src/Response/Stringable.php @@ -19,6 +19,7 @@ private function __construct() { } + #[\NoDiscard] public function __invoke(Response $response): Content { $status = Str::of("HTTP/%s %s %s\n")->sprintf( @@ -48,6 +49,7 @@ public function __invoke(Response $response): Content /** * @psalm-pure */ + #[\NoDiscard] public static function new(): self { return new self; diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 5d3e187c..2a0beb1a 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -35,6 +35,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of( Url $url, Method $method, @@ -61,51 +62,61 @@ public static function of( ); } + #[\NoDiscard] public function protocolVersion(): ProtocolVersion { return $this->protocolVersion; } + #[\NoDiscard] public function headers(): Headers { return $this->headers; } + #[\NoDiscard] public function body(): Content { return $this->body; } + #[\NoDiscard] public function url(): Url { return $this->url; } + #[\NoDiscard] public function method(): Method { return $this->method; } + #[\NoDiscard] public function environment(): Environment { return $this->environment; } + #[\NoDiscard] public function cookies(): Cookies { return $this->cookies; } + #[\NoDiscard] public function query(): Query { return $this->query; } + #[\NoDiscard] public function form(): Form { return $this->form; } + #[\NoDiscard] public function files(): Files { return $this->files; diff --git a/src/ServerRequest/Cookies.php b/src/ServerRequest/Cookies.php index 9a44fc3d..639983fa 100644 --- a/src/ServerRequest/Cookies.php +++ b/src/ServerRequest/Cookies.php @@ -33,6 +33,7 @@ private function __construct(?Map $cookies = null) * * @param Map|null $cookies */ + #[\NoDiscard] public static function of(?Map $cookies = null): self { return new self($cookies); @@ -41,11 +42,13 @@ public static function of(?Map $cookies = null): self /** * @return Maybe */ + #[\NoDiscard] public function get(string $name): Maybe { return $this->cookies->get($name); } + #[\NoDiscard] public function contains(string $name): bool { return $this->cookies->contains($name); @@ -54,6 +57,7 @@ public function contains(string $name): bool /** * @param callable(string, string): void $function */ + #[\NoDiscard] public function foreach(callable $function): SideEffect { return $this->cookies->foreach($function); @@ -67,12 +71,14 @@ public function foreach(callable $function): SideEffect * * @return R */ + #[\NoDiscard] public function reduce($carry, callable $reducer) { return $this->cookies->reduce($carry, $reducer); } #[\Override] + #[\NoDiscard] public function count(): int { return $this->cookies->size(); diff --git a/src/ServerRequest/Environment.php b/src/ServerRequest/Environment.php index 2c803a4e..2c3c87a9 100644 --- a/src/ServerRequest/Environment.php +++ b/src/ServerRequest/Environment.php @@ -33,6 +33,7 @@ private function __construct(?Map $variables = null) * * @param Map|null $variables */ + #[\NoDiscard] public static function of(?Map $variables = null): self { return new self($variables); @@ -41,11 +42,13 @@ public static function of(?Map $variables = null): self /** * @return Maybe */ + #[\NoDiscard] public function get(string $name): Maybe { return $this->variables->get($name); } + #[\NoDiscard] public function contains(string $name): bool { return $this->variables->contains($name); @@ -54,6 +57,7 @@ public function contains(string $name): bool /** * @param callable(string, string): void $function */ + #[\NoDiscard] public function foreach(callable $function): SideEffect { return $this->variables->foreach($function); @@ -67,12 +71,14 @@ public function foreach(callable $function): SideEffect * * @return R */ + #[\NoDiscard] public function reduce($carry, callable $reducer) { return $this->variables->reduce($carry, $reducer); } #[\Override] + #[\NoDiscard] public function count(): int { return $this->variables->size(); diff --git a/src/ServerRequest/Files.php b/src/ServerRequest/Files.php index 284463f1..42379d06 100644 --- a/src/ServerRequest/Files.php +++ b/src/ServerRequest/Files.php @@ -23,6 +23,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(array $files): self { return new self($files); @@ -33,6 +34,7 @@ public static function of(array $files): self * * @return Either */ + #[\NoDiscard] public function get(int|string $key): Either { if (!\array_key_exists($key, $this->files)) { @@ -62,6 +64,7 @@ public function get(int|string $key): Either /** * @param non-empty-string $name */ + #[\NoDiscard] public function under(string $name): self { /** @var mixed */ @@ -81,6 +84,7 @@ public function under(string $name): self * * @return Sequence */ + #[\NoDiscard] public function list(string $name): Sequence { /** @var mixed */ diff --git a/src/ServerRequest/Form.php b/src/ServerRequest/Form.php index e0c0fc71..f07009a1 100644 --- a/src/ServerRequest/Form.php +++ b/src/ServerRequest/Form.php @@ -18,6 +18,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(array $data): self { return new self($data); @@ -26,6 +27,7 @@ public static function of(array $data): self /** * @return Maybe */ + #[\NoDiscard] public function get(int|string $key): Maybe { if (!\array_key_exists($key, $this->data)) { @@ -40,6 +42,7 @@ public function get(int|string $key): Maybe /** * @return Maybe */ + #[\NoDiscard] public function list(int|string $key): Maybe { /** @psalm-suppress InvalidArgument Psalm doesn't understand the filters */ @@ -53,6 +56,7 @@ public function list(int|string $key): Maybe /** * @return Maybe */ + #[\NoDiscard] public function dictionary(int|string $key): Maybe { /** @psalm-suppress InvalidArgument Psalm doesn't understand the filters */ @@ -63,6 +67,7 @@ public function dictionary(int|string $key): Maybe ->map(static fn(array $data) => new self($data)); } + #[\NoDiscard] public function contains(int|string $key): bool { return $this->get($key)->match( @@ -71,12 +76,14 @@ public function contains(int|string $key): bool ); } + #[\NoDiscard] public function data(): array { return $this->data; } #[\Override] + #[\NoDiscard] public function count(): int { return \count($this->data); diff --git a/src/ServerRequest/Query.php b/src/ServerRequest/Query.php index daf08563..b03795d6 100644 --- a/src/ServerRequest/Query.php +++ b/src/ServerRequest/Query.php @@ -19,6 +19,7 @@ private function __construct( /** * @psalm-pure */ + #[\NoDiscard] public static function of(array $data): self { return new self($data); @@ -27,6 +28,7 @@ public static function of(array $data): self /** * @return Maybe */ + #[\NoDiscard] public function get(int|string $key): Maybe { if (!\array_key_exists($key, $this->data)) { @@ -41,6 +43,7 @@ public function get(int|string $key): Maybe /** * @return Maybe */ + #[\NoDiscard] public function list(int|string $key): Maybe { /** @psalm-suppress InvalidArgument Psalm doesn't understand the filters */ @@ -54,6 +57,7 @@ public function list(int|string $key): Maybe /** * @return Maybe */ + #[\NoDiscard] public function dictionary(int|string $key): Maybe { /** @psalm-suppress InvalidArgument Psalm doesn't understand the filters */ @@ -64,6 +68,7 @@ public function dictionary(int|string $key): Maybe ->map(static fn(array $data) => new self($data)); } + #[\NoDiscard] public function contains(int|string $key): bool { return $this->get($key)->match( @@ -72,12 +77,14 @@ public function contains(int|string $key): bool ); } + #[\NoDiscard] public function data(): array { return $this->data; } #[\Override] + #[\NoDiscard] public function count(): int { return \count($this->data); diff --git a/src/ServerRequest/Stringable.php b/src/ServerRequest/Stringable.php index ded46eda..a1706281 100644 --- a/src/ServerRequest/Stringable.php +++ b/src/ServerRequest/Stringable.php @@ -19,6 +19,7 @@ private function __construct() { } + #[\NoDiscard] public function __invoke(ServerRequest $request): Content { $status = Str::of("%s %s%s HTTP/%s\n")->sprintf( @@ -48,6 +49,7 @@ public function __invoke(ServerRequest $request): Content /** * @psalm-pure */ + #[\NoDiscard] public static function new(): self { return new self; diff --git a/src/Time/Format/Http.php b/src/Time/Format/Http.php index 506a29c8..050cdea7 100644 --- a/src/Time/Format/Http.php +++ b/src/Time/Format/Http.php @@ -10,6 +10,7 @@ final class Http /** * @psalm-pure */ + #[\NoDiscard] public static function new(): Format { return Format::of('D, d M Y H:i:s \G\M\T'); From 5fdd34d686cba5e7cb095e25ff062ae28d1d5ebe Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 19:32:58 +0100 Subject: [PATCH 2/2] fix warnings --- tests/Header/ContentType/BoundaryTest.php | 2 +- tests/MethodTest.php | 2 +- tests/Response/StatusCodeTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Header/ContentType/BoundaryTest.php b/tests/Header/ContentType/BoundaryTest.php index ed817b11..ee00436c 100644 --- a/tests/Header/ContentType/BoundaryTest.php +++ b/tests/Header/ContentType/BoundaryTest.php @@ -34,7 +34,7 @@ public function testThrowWhenRandomString() )) ->then(function($random) { try { - Boundary::of($random); + $_ = Boundary::of($random); $this->fail('it should throw'); } catch (DomainException $e) { $this->assertSame($random, $e->getMessage()); diff --git a/tests/MethodTest.php b/tests/MethodTest.php index cf328bea..03f5ce42 100644 --- a/tests/MethodTest.php +++ b/tests/MethodTest.php @@ -30,7 +30,7 @@ public function testThrowWhenInvalidMethod() { $this->expectException(\UnhandledMatchError::class); - Method::of('get'); + $_ = Method::of('get'); } public function methods(): Set diff --git a/tests/Response/StatusCodeTest.php b/tests/Response/StatusCodeTest.php index 08ea0b93..8b327596 100644 --- a/tests/Response/StatusCodeTest.php +++ b/tests/Response/StatusCodeTest.php @@ -24,7 +24,7 @@ public function testInterface() public function testThrowWhenInvalidStatusCode() { try { - StatusCode::of(42); //sadly + $_ = StatusCode::of(42); //sadly $this->fail('it should throw'); } catch (\Throwable $e) {