From c4d748d77cc596f78d53629f3b872484baae2a0e Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 25 Jan 2026 17:12:47 +0100 Subject: [PATCH] add NoDiscard attributes --- psalm.xml | 3 +++ src/Files.php | 8 ++++++++ src/Files/Directory.php | 3 +++ src/Files/File.php | 5 +++++ src/Files/Name.php | 3 +++ src/Files/Read.php | 7 +++++++ src/Files/Temporary.php | 6 ++++++ src/Files/Temporary/Pull.php | 5 +++++ src/Files/Temporary/Push.php | 3 +++ src/Files/Write.php | 4 ++++ src/Frame.php | 10 ++++++++++ src/Frame/Provider/Chunk.php | 2 ++ src/IO.php | 6 ++++++ src/Sockets.php | 4 ++++ src/Sockets/Clients.php | 3 +++ src/Sockets/Clients/Client.php | 11 +++++++++++ src/Sockets/Clients/Client/Frames.php | 3 +++ src/Sockets/Clients/Client/Frames/Lazy.php | 2 ++ src/Sockets/Internet/Transport.php | 11 +++++++++++ src/Sockets/Servers.php | 4 ++++ src/Sockets/Servers/Server.php | 7 +++++++ src/Sockets/Servers/Server/Pool.php | 3 +++ src/Sockets/Unix/Address.php | 2 ++ src/Stream/Size.php | 5 +++++ src/Stream/Size/Unit.php | 4 ++++ src/Streams.php | 2 ++ src/Streams/Stream.php | 4 ++++ src/Streams/Stream/Read.php | 11 +++++++++++ src/Streams/Stream/Read/Frames.php | 3 +++ src/Streams/Stream/Read/Frames/Lazy.php | 3 +++ src/Streams/Stream/Read/Pool.php | 8 ++++++++ src/Streams/Stream/Write.php | 5 +++++ 32 files changed, 160 insertions(+) diff --git a/psalm.xml b/psalm.xml index 78df975..a2dbf3d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -17,4 +17,7 @@ + + + diff --git a/src/Files.php b/src/Files.php index 9e6dbf6..8392716 100644 --- a/src/Files.php +++ b/src/Files.php @@ -31,16 +31,19 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Capabilities $capabilities): self { return new self($capabilities); } + #[\NoDiscard] public function read(Path $path): Read { return Read::of($this->capabilities, $path); } + #[\NoDiscard] public function write(Path $path): Write { return Write::of($this->capabilities, $path); @@ -49,6 +52,7 @@ public function write(Path $path): Write /** * @return Maybe */ + #[\NoDiscard] public function require(Path $path): Maybe { return $this->capabilities->files()->require($path); @@ -59,6 +63,7 @@ public function require(Path $path): Maybe * * @return Attempt */ + #[\NoDiscard] public function temporary(Sequence $chunks): Attempt { $capabilities = $this->capabilities; @@ -77,6 +82,7 @@ public function temporary(Sequence $chunks): Attempt /** * @return Attempt */ + #[\NoDiscard] public function access(Path $path): Attempt { return $this @@ -93,6 +99,7 @@ public function access(Path $path): Attempt /** * @return Attempt */ + #[\NoDiscard] public function create(Path $path): Attempt { return $this @@ -105,6 +112,7 @@ public function create(Path $path): Attempt }); } + #[\NoDiscard] public function exists(Path $path): bool { return $this->capabilities->files()->exists($path); diff --git a/src/Files/Directory.php b/src/Files/Directory.php index 2dc8d80..b675b44 100644 --- a/src/Files/Directory.php +++ b/src/Files/Directory.php @@ -22,6 +22,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Path $path, @@ -36,6 +37,7 @@ public static function of( /** * @return Sequence */ + #[\NoDiscard] public function list(): Sequence { return $this @@ -47,6 +49,7 @@ public function list(): Sequence /** * @return Attempt */ + #[\NoDiscard] public function remove(): Attempt { return $this diff --git a/src/Files/File.php b/src/Files/File.php index 686bcfb..d71e8e5 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -21,6 +21,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Path $path, @@ -28,11 +29,13 @@ public static function of( return new self($capabilities, $path); } + #[\NoDiscard] public function read(): Read { return Read::of($this->capabilities, $this->path); } + #[\NoDiscard] public function write(): Write { return Write::of($this->capabilities, $this->path); @@ -41,6 +44,7 @@ public function write(): Write /** * @return Attempt */ + #[\NoDiscard] public function remove(): Attempt { return $this @@ -52,6 +56,7 @@ public function remove(): Attempt /** * @return Attempt */ + #[\NoDiscard] public function mediaType(): Attempt { return $this diff --git a/src/Files/Name.php b/src/Files/Name.php index 3188840..9a00a51 100644 --- a/src/Files/Name.php +++ b/src/Files/Name.php @@ -22,11 +22,13 @@ private function __construct( * * @param non-empty-string $name */ + #[\NoDiscard] public static function of(string $name, Kind $kind): self { return new self($name, $kind); } + #[\NoDiscard] public function kind(): Kind { return $this->kind; @@ -35,6 +37,7 @@ public function kind(): Kind /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return $this->name; diff --git a/src/Files/Read.php b/src/Files/Read.php index 9182811..948271d 100644 --- a/src/Files/Read.php +++ b/src/Files/Read.php @@ -34,6 +34,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Path $path, @@ -55,6 +56,7 @@ public static function of( /** * @internal */ + #[\NoDiscard] public static function temporary( Capabilities $capabilities, Internal\Stream $stream, @@ -73,6 +75,7 @@ public static function temporary( /** * @psalm-mutation-free */ + #[\NoDiscard] public function toEncoding(Str\Encoding $encoding): self { return new self( @@ -91,6 +94,7 @@ public function toEncoding(Str\Encoding $encoding): self * * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -104,6 +108,7 @@ public function watch(): self /** * @return Maybe */ + #[\NoDiscard] public function size(): Maybe { return ($this->load)()->size(); @@ -114,6 +119,7 @@ public function size(): Maybe * * @return Sequence */ + #[\NoDiscard] public function chunks(int $size): Sequence { $load = $this->load; @@ -167,6 +173,7 @@ public function chunks(int $size): Sequence /** * @return Sequence */ + #[\NoDiscard] public function lines(): Sequence { $load = $this->load; diff --git a/src/Files/Temporary.php b/src/Files/Temporary.php index a687ff7..31a94d3 100644 --- a/src/Files/Temporary.php +++ b/src/Files/Temporary.php @@ -25,6 +25,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Internal\Stream $stream, @@ -38,11 +39,13 @@ public static function of( * * @internal */ + #[\NoDiscard] public function internal(): Internal\Stream { return $this->stream; } + #[\NoDiscard] public function read(): Read { return Read::temporary($this->capabilities, $this->stream); @@ -51,6 +54,7 @@ public function read(): Read /** * @return Attempt */ + #[\NoDiscard] public function pull(): Attempt { return $this->stream->rewind()->map( @@ -58,6 +62,7 @@ public function pull(): Attempt ); } + #[\NoDiscard] public function push(): Push { return Push::of($this->capabilities, $this->stream); @@ -66,6 +71,7 @@ public function push(): Push /** * @return Attempt */ + #[\NoDiscard] public function close(): Attempt { return $this->stream->close(); diff --git a/src/Files/Temporary/Pull.php b/src/Files/Temporary/Pull.php index 6be53db..27573af 100644 --- a/src/Files/Temporary/Pull.php +++ b/src/Files/Temporary/Pull.php @@ -30,6 +30,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Internal\Stream $stream, @@ -47,6 +48,7 @@ public static function of( /** * @psalm-mutation-free */ + #[\NoDiscard] public function toEncoding(Str\Encoding $encoding): self { return new self( @@ -64,6 +66,7 @@ public function toEncoding(Str\Encoding $encoding): self * * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -76,6 +79,7 @@ public function watch(): self /** * @return Maybe */ + #[\NoDiscard] public function size(): Maybe { return $this->stream->size(); @@ -86,6 +90,7 @@ public function size(): Maybe * * @return Attempt */ + #[\NoDiscard] public function chunk(int $size): Attempt { $stream = $this->stream; diff --git a/src/Files/Temporary/Push.php b/src/Files/Temporary/Push.php index 16235b2..5934e6a 100644 --- a/src/Files/Temporary/Push.php +++ b/src/Files/Temporary/Push.php @@ -25,6 +25,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Internal\Stream $stream, @@ -43,6 +44,7 @@ public static function of( * * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -54,6 +56,7 @@ public function watch(): self /** * @return Attempt */ + #[\NoDiscard] public function chunk(Str $chunk): Attempt { $stream = $this->stream; diff --git a/src/Files/Write.php b/src/Files/Write.php index d4cda91..65893e8 100644 --- a/src/Files/Write.php +++ b/src/Files/Write.php @@ -35,6 +35,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Capabilities $capabilities, Path $path): self { return new self( @@ -51,6 +52,7 @@ public static function of(Capabilities $capabilities, Path $path): self /** * @internal */ + #[\NoDiscard] public static function temporary( Capabilities $capabilities, Internal\Stream $stream, @@ -71,6 +73,7 @@ public static function temporary( * * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -86,6 +89,7 @@ public function watch(): self * * @return Attempt */ + #[\NoDiscard] public function sink(Sequence $chunks): Attempt { $stream = ($this->load)(); diff --git a/src/Frame.php b/src/Frame.php index 15cb6b9..1371c04 100644 --- a/src/Frame.php +++ b/src/Frame.php @@ -51,6 +51,7 @@ public function __invoke(Reader|Reader\Buffer $reader): Attempt * * @return self */ + #[\NoDiscard] public static function just(mixed $value): self { return new self(M::just($value)); @@ -64,6 +65,7 @@ public static function just(mixed $value): self * * @return self */ + #[\NoDiscard] public static function maybe(Maybe $value): self { return new self(M::of($value)); @@ -74,6 +76,7 @@ public static function maybe(Maybe $value): self * * @param int<1, max> $size */ + #[\NoDiscard] public static function chunk(int $size): Frame\Provider\Chunk { return Frame\Provider\Chunk::of( @@ -87,6 +90,7 @@ public static function chunk(int $size): Frame\Provider\Chunk * * @return self */ + #[\NoDiscard] public static function line(): self { return new self(Line::new()); @@ -100,6 +104,7 @@ public static function line(): self * * @return self */ + #[\NoDiscard] public static function compose( callable $map, self $first, @@ -127,6 +132,7 @@ public static function compose( * * @return self>> */ + #[\NoDiscard] public static function sequence(self $frame): self { return new self(Sequence::of($frame)); @@ -149,6 +155,7 @@ public static function sequence(self $frame): self * * @return self */ + #[\NoDiscard] public static function buffer(int $size, self $frame): self { /** @psalm-suppress ImpurePropertyFetch It's safe to access the implementation */ @@ -162,6 +169,7 @@ public static function buffer(int $size, self $frame): self * * @return self */ + #[\NoDiscard] public function filter(callable $predicate): self { return new self(Frame\Filter::of( @@ -179,6 +187,7 @@ public function filter(callable $predicate): self * * @return self */ + #[\NoDiscard] public function map(callable $map): self { return new self(Frame\Map::of( @@ -196,6 +205,7 @@ public function map(callable $map): self * * @return self */ + #[\NoDiscard] public function flatMap(callable $map): self { return new self(Frame\FlatMap::of( diff --git a/src/Frame/Provider/Chunk.php b/src/Frame/Provider/Chunk.php index c43ad87..b09ace5 100644 --- a/src/Frame/Provider/Chunk.php +++ b/src/Frame/Provider/Chunk.php @@ -43,6 +43,7 @@ public static function of( * * @return Frame */ + #[\NoDiscard] public function strict(): Frame { $size = $this->size; @@ -57,6 +58,7 @@ public function strict(): Frame * * @return Frame */ + #[\NoDiscard] public function loose(): Frame { /** @var Frame */ diff --git a/src/IO.php b/src/IO.php index 84b6271..e9825b5 100644 --- a/src/IO.php +++ b/src/IO.php @@ -13,6 +13,7 @@ private function __construct( ) { } + #[\NoDiscard] public static function fromAmbientAuthority(): self { return new self(Capabilities::fromAmbientAuthority()); @@ -23,6 +24,7 @@ public static function fromAmbientAuthority(): self * * @internal */ + #[\NoDiscard] public static function async(self $io, Clock $clock): self { return new self(Capabilities::async( @@ -36,6 +38,7 @@ public static function async(self $io, Clock $clock): self * * @internal */ + #[\NoDiscard] public static function simulation( self $io, Simulation\Disk $disk, @@ -46,16 +49,19 @@ public static function simulation( )); } + #[\NoDiscard] public function files(): Files { return Files::of($this->capabilities); } + #[\NoDiscard] public function streams(): Streams { return Streams::of($this->capabilities); } + #[\NoDiscard] public function sockets(): Sockets { return Sockets::of($this->capabilities); diff --git a/src/Sockets.php b/src/Sockets.php index 50e2ba3..f0d65a5 100644 --- a/src/Sockets.php +++ b/src/Sockets.php @@ -21,17 +21,20 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, ): self { return new self($capabilities); } + #[\NoDiscard] public function clients(): Clients { return Clients::of($this->capabilities); } + #[\NoDiscard] public function servers(): Servers { return Servers::of($this->capabilities); @@ -40,6 +43,7 @@ public function servers(): Servers /** * @return Attempt */ + #[\NoDiscard] public function pair(): Attempt { return $this->capabilities->sockets()->pair()->map( diff --git a/src/Sockets/Clients.php b/src/Sockets/Clients.php index e1b5cb7..1fb3e71 100644 --- a/src/Sockets/Clients.php +++ b/src/Sockets/Clients.php @@ -23,6 +23,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, ): self { @@ -32,6 +33,7 @@ public static function of( /** * @return Attempt */ + #[\NoDiscard] public function internet(Transport $transport, Authority $authority): Attempt { return $this @@ -50,6 +52,7 @@ public function internet(Transport $transport, Authority $authority): Attempt /** * @return Attempt */ + #[\NoDiscard] public function unix(Address $address): Attempt { return $this diff --git a/src/Sockets/Clients/Client.php b/src/Sockets/Clients/Client.php index 9c893d7..a660732 100644 --- a/src/Sockets/Clients/Client.php +++ b/src/Sockets/Clients/Client.php @@ -28,6 +28,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Stream $stream): self { return new self( @@ -40,6 +41,7 @@ public static function of(Stream $stream): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function toEncoding(Str\Encoding $encoding): self { return new self( @@ -52,6 +54,7 @@ public function toEncoding(Str\Encoding $encoding): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -64,6 +67,7 @@ public function watch(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function timeoutAfter(Period $period): self { return new self( @@ -76,6 +80,7 @@ public function timeoutAfter(Period $period): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function poll(): self { return $this->timeoutAfter(Period::second(0)); @@ -93,6 +98,7 @@ public function poll(): self * * @param callable(): Sequence $chunks */ + #[\NoDiscard] public function heartbeatWith(callable $chunks): self { return new self( @@ -116,6 +122,7 @@ public function heartbeatWith(callable $chunks): self * * @param callable(): bool $abort */ + #[\NoDiscard] public function abortWhen(callable $abort): self { return new self( @@ -130,6 +137,7 @@ public function abortWhen(callable $abort): self * * @return Attempt */ + #[\NoDiscard] public function sink(Sequence $chunks): Attempt { return $this->write->sink($chunks); @@ -140,6 +148,7 @@ public function sink(Sequence $chunks): Attempt * * @return Attempt */ + #[\NoDiscard] public function sinkAttempts(Sequence $chunks): Attempt { return $this->write->sinkAttempts($chunks); @@ -152,6 +161,7 @@ public function sinkAttempts(Sequence $chunks): Attempt * * @return Frames */ + #[\NoDiscard] public function frames(Frame $frame): Frames { return Frames::of($this->read->frames($frame)); @@ -160,6 +170,7 @@ public function frames(Frame $frame): Frames /** * @return Attempt */ + #[\NoDiscard] public function close(): Attempt { return $this->stream->close(); diff --git a/src/Sockets/Clients/Client/Frames.php b/src/Sockets/Clients/Client/Frames.php index 6ba00ed..26dc765 100644 --- a/src/Sockets/Clients/Client/Frames.php +++ b/src/Sockets/Clients/Client/Frames.php @@ -30,6 +30,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function of(Stream $frames): self { return new self($frames); @@ -38,6 +39,7 @@ public static function of(Stream $frames): self /** * @return Attempt */ + #[\NoDiscard] public function one(): Attempt { return $this->frames->one(); @@ -46,6 +48,7 @@ public function one(): Attempt /** * @return Lazy */ + #[\NoDiscard] public function lazy(): Lazy { return Lazy::of($this->frames->lazy()); diff --git a/src/Sockets/Clients/Client/Frames/Lazy.php b/src/Sockets/Clients/Client/Frames/Lazy.php index 32a4ff3..42bbd7c 100644 --- a/src/Sockets/Clients/Client/Frames/Lazy.php +++ b/src/Sockets/Clients/Client/Frames/Lazy.php @@ -27,6 +27,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function of(Stream $frames): self { return new self($frames); @@ -35,6 +36,7 @@ public static function of(Stream $frames): self /** * @return Sequence */ + #[\NoDiscard] public function sequence(): Sequence { return $this->frames->sequence(); diff --git a/src/Sockets/Internet/Transport.php b/src/Sockets/Internet/Transport.php index e9639df..4b8ae81 100644 --- a/src/Sockets/Internet/Transport.php +++ b/src/Sockets/Internet/Transport.php @@ -25,41 +25,49 @@ private function __construct(string $transport) $this->options = Map::of(); } + #[\NoDiscard] public static function tcp(): self { return new self('tcp'); } + #[\NoDiscard] public static function ssl(): self { return new self('ssl'); } + #[\NoDiscard] public static function sslv3(): self { return new self('sslv3'); } + #[\NoDiscard] public static function sslv2(): self { return new self('sslv2'); } + #[\NoDiscard] public static function tls(): self { return new self('tls'); } + #[\NoDiscard] public static function tlsv10(): self { return new self('tlsv1.0'); } + #[\NoDiscard] public static function tlsv11(): self { return new self('tlsv1.1'); } + #[\NoDiscard] public static function tlsv12(): self { return new self('tlsv1.2'); @@ -68,6 +76,7 @@ public static function tlsv12(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function withOption(string $key, int|bool|float|string|array $value): self { $self = clone $this; @@ -79,11 +88,13 @@ public function withOption(string $key, int|bool|float|string|array $value): sel /** * @return Map */ + #[\NoDiscard] public function options(): Map { return $this->options; } + #[\NoDiscard] public function toString(): string { return $this->transport; diff --git a/src/Sockets/Servers.php b/src/Sockets/Servers.php index 0dbb574..5b56ac7 100644 --- a/src/Sockets/Servers.php +++ b/src/Sockets/Servers.php @@ -23,6 +23,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Capabilities $capabilities): self { return new self($capabilities); @@ -31,6 +32,7 @@ public static function of(Capabilities $capabilities): self /** * @return Attempt */ + #[\NoDiscard] public function internet(Transport $transport, IP $ip, Port $port): Attempt { return $this @@ -48,6 +50,7 @@ public function internet(Transport $transport, IP $ip, Port $port): Attempt /** * @return Attempt */ + #[\NoDiscard] public function unix(Address $address): Attempt { return $this @@ -65,6 +68,7 @@ public function unix(Address $address): Attempt /** * @return Attempt */ + #[\NoDiscard] public function takeOver(Address $address): Attempt { return $this diff --git a/src/Sockets/Servers/Server.php b/src/Sockets/Servers/Server.php index b7a2e1d..22cb0d5 100644 --- a/src/Sockets/Servers/Server.php +++ b/src/Sockets/Servers/Server.php @@ -31,6 +31,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Watch $watch, @@ -42,6 +43,7 @@ public static function of( /** * @internal */ + #[\NoDiscard] public function unwrap(): Watch { return $this->watch; @@ -50,6 +52,7 @@ public function unwrap(): Watch /** * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -62,6 +65,7 @@ public function watch(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function timeoutAfter(Period $period): self { return new self( @@ -74,6 +78,7 @@ public function timeoutAfter(Period $period): self /** * @return Attempt */ + #[\NoDiscard] public function accept(): Attempt { $socket = $this->socket; @@ -97,6 +102,7 @@ public function accept(): Attempt )); } + #[\NoDiscard] public function pool(self $server): Pool { return Pool::of($this->capabilities, $this->watch->forRead( @@ -107,6 +113,7 @@ public function pool(self $server): Pool /** * @return Attempt */ + #[\NoDiscard] public function close(): Attempt { return $this->socket->close(); diff --git a/src/Sockets/Servers/Server/Pool.php b/src/Sockets/Servers/Server/Pool.php index 8e8dc09..726d87e 100644 --- a/src/Sockets/Servers/Server/Pool.php +++ b/src/Sockets/Servers/Server/Pool.php @@ -27,6 +27,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Capabilities $capabilities, Watch $watch): self { return new self($capabilities, $watch); @@ -35,6 +36,7 @@ public static function of(Capabilities $capabilities, Watch $watch): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function with(Server $server): self { return new self( @@ -46,6 +48,7 @@ public function with(Server $server): self /** * @return Sequence */ + #[\NoDiscard] public function accept(): Sequence { return ($this->watch)() diff --git a/src/Sockets/Unix/Address.php b/src/Sockets/Unix/Address.php index a1df135..20ae059 100644 --- a/src/Sockets/Unix/Address.php +++ b/src/Sockets/Unix/Address.php @@ -17,11 +17,13 @@ private function __construct(private Path $path) /** * @psalm-pure */ + #[\NoDiscard] public static function of(Path $path): self { return new self($path); } + #[\NoDiscard] public function toString(): string { /** @var array{dirname: string, filename: string} */ diff --git a/src/Stream/Size.php b/src/Stream/Size.php index 9b9f80f..6ef5dcc 100644 --- a/src/Stream/Size.php +++ b/src/Stream/Size.php @@ -19,11 +19,13 @@ private function __construct( * * @param int<0, max> $value */ + #[\NoDiscard] public static function of(int $value): self { return new self($value); } + #[\NoDiscard] public function lessThan(self $size): bool { return $this->value < $size->value; @@ -32,16 +34,19 @@ public function lessThan(self $size): bool /** * @return int<0, max> */ + #[\NoDiscard] public function toInt(): int { return $this->value; } + #[\NoDiscard] public function unit(): Size\Unit { return Size\Unit::for($this->value); } + #[\NoDiscard] public function toString(): string { return Size\Unit::format($this->value); diff --git a/src/Stream/Size/Unit.php b/src/Stream/Size/Unit.php index e3b4b07..3d17850 100644 --- a/src/Stream/Size/Unit.php +++ b/src/Stream/Size/Unit.php @@ -22,6 +22,7 @@ enum Unit * * @param int<0, max> $size */ + #[\NoDiscard] public static function for(int $size): self { if ($size < 1024) { @@ -52,6 +53,7 @@ public static function for(int $size): self * * @param int<0, max> $size */ + #[\NoDiscard] public static function format(int $size): string { $unit = self::for($size); @@ -71,6 +73,7 @@ public static function format(int $size): string * * @return int<0, max> */ + #[\NoDiscard] public function times(int $value): int { return match ($this) { @@ -82,6 +85,7 @@ public function times(int $value): int /** * @param int<0, max> $value */ + #[\NoDiscard] public function of(int $value): Size { return Size::of($this->times($value)); diff --git a/src/Streams.php b/src/Streams.php index 9c118cc..6295176 100644 --- a/src/Streams.php +++ b/src/Streams.php @@ -18,6 +18,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Capabilities $capabilities): self { return new self($capabilities); @@ -26,6 +27,7 @@ public static function of(Capabilities $capabilities): self /** * @param resource $resource */ + #[\NoDiscard] public function acquire($resource): Stream { return Stream::of( diff --git a/src/Streams/Stream.php b/src/Streams/Stream.php index f3393ab..3573593 100644 --- a/src/Streams/Stream.php +++ b/src/Streams/Stream.php @@ -25,6 +25,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Internal\Stream $stream, @@ -32,6 +33,7 @@ public static function of( return new self($capabilities, $stream); } + #[\NoDiscard] public function read(): Read { return Read::of( @@ -41,6 +43,7 @@ public function read(): Read ); } + #[\NoDiscard] public function write(): Write { return Write::of($this->capabilities->watch(), $this->stream); @@ -49,6 +52,7 @@ public function write(): Write /** * @return Attempt */ + #[\NoDiscard] public function close(): Attempt { return $this->stream->close(); diff --git a/src/Streams/Stream/Read.php b/src/Streams/Stream/Read.php index 00b2c01..5c61013 100644 --- a/src/Streams/Stream/Read.php +++ b/src/Streams/Stream/Read.php @@ -40,6 +40,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of( Write $write, Capabilities $capabilities, @@ -65,6 +66,7 @@ public static function of( /** * @internal */ + #[\NoDiscard] public function internal(): Stream { return $this->stream; @@ -78,6 +80,7 @@ public function internal(): Stream * * @psalm-mutation-free */ + #[\NoDiscard] public function nonBlocking(): self { return new self( @@ -95,6 +98,7 @@ public function nonBlocking(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function toEncoding(Str\Encoding $encoding): self { return new self( @@ -112,6 +116,7 @@ public function toEncoding(Str\Encoding $encoding): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -129,6 +134,7 @@ public function watch(): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function timeoutAfter(Period $period): self { return new self( @@ -146,6 +152,7 @@ public function timeoutAfter(Period $period): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function poll(): self { return $this->timeoutAfter(Period::second(0)); @@ -163,6 +170,7 @@ public function poll(): self * * @param callable(): Sequence $provide */ + #[\NoDiscard] public function heartbeatWith(callable $provide): self { return new self( @@ -190,6 +198,7 @@ public function heartbeatWith(callable $provide): self * * @param callable(): bool $abort */ + #[\NoDiscard] public function abortWhen(callable $abort): self { return new self( @@ -211,6 +220,7 @@ public function abortWhen(callable $abort): self * * @return Pool */ + #[\NoDiscard] public function pool(mixed $id): Pool { return Pool::of( @@ -227,6 +237,7 @@ public function pool(mixed $id): Pool * * @return Frames */ + #[\NoDiscard] public function frames(Frame $frame): Frames { return Frames::of( diff --git a/src/Streams/Stream/Read/Frames.php b/src/Streams/Stream/Read/Frames.php index 3886b60..f3b0fcf 100644 --- a/src/Streams/Stream/Read/Frames.php +++ b/src/Streams/Stream/Read/Frames.php @@ -53,6 +53,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function of( Write $write, Stream $stream, @@ -78,6 +79,7 @@ public static function of( /** * @return Attempt */ + #[\NoDiscard] public function one(): Attempt { $stream = $this->stream; @@ -113,6 +115,7 @@ public function one(): Attempt /** * @return Lazy */ + #[\NoDiscard] public function lazy(): Lazy { return Lazy::of( diff --git a/src/Streams/Stream/Read/Frames/Lazy.php b/src/Streams/Stream/Read/Frames/Lazy.php index 24d75b8..8c267a1 100644 --- a/src/Streams/Stream/Read/Frames/Lazy.php +++ b/src/Streams/Stream/Read/Frames/Lazy.php @@ -51,6 +51,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function of( Write $write, Stream $stream, @@ -79,6 +80,7 @@ public static function of( * * @return self */ + #[\NoDiscard] public function rewindable(): self { return new self( @@ -97,6 +99,7 @@ public function rewindable(): self /** * @return Sequence */ + #[\NoDiscard] public function sequence(): Sequence { $write = $this->write; diff --git a/src/Streams/Stream/Read/Pool.php b/src/Streams/Stream/Read/Pool.php index baddd0c..7825f53 100644 --- a/src/Streams/Stream/Read/Pool.php +++ b/src/Streams/Stream/Read/Pool.php @@ -42,6 +42,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function of( Capabilities $capabilities, Read $stream, @@ -63,6 +64,7 @@ public static function of( * * @return self */ + #[\NoDiscard] public function with(mixed $id, Read $stream): self { /** @psalm-suppress InvalidArgument Due to the id union */ @@ -78,6 +80,7 @@ public function with(mixed $id, Read $stream): self /** * @return self */ + #[\NoDiscard] public function poll(): self { return $this->timeoutAfter(Period::second(0)); @@ -86,6 +89,7 @@ public function poll(): self /** * @return self */ + #[\NoDiscard] public function watch(): self { return new self( @@ -100,6 +104,7 @@ public function watch(): self /** * @return self */ + #[\NoDiscard] public function timeoutAfter(Period $timeout): self { return new self( @@ -114,6 +119,7 @@ public function timeoutAfter(Period $timeout): self /** * @return self */ + #[\NoDiscard] public function toEncoding(Str\Encoding $encoding): self { return new self( @@ -128,6 +134,7 @@ public function toEncoding(Str\Encoding $encoding): self /** * @return self */ + #[\NoDiscard] public function nonBlocking(): self { return new self( @@ -142,6 +149,7 @@ public function nonBlocking(): self /** * @return Sequence> */ + #[\NoDiscard] public function chunks(): Sequence { $blocking = $this->blocking; diff --git a/src/Streams/Stream/Write.php b/src/Streams/Stream/Write.php index 9a60839..9643e72 100644 --- a/src/Streams/Stream/Write.php +++ b/src/Streams/Stream/Write.php @@ -32,6 +32,7 @@ private function __construct( /** * @internal */ + #[\NoDiscard] public static function of(Watch $watch, Stream $stream): self { return new self( @@ -52,6 +53,7 @@ public static function of(Watch $watch, Stream $stream): self * * @param callable(): bool $abort */ + #[\NoDiscard] public function abortWhen(callable $abort): self { return new self( @@ -65,6 +67,7 @@ public function abortWhen(callable $abort): self /** * @psalm-mutation-free */ + #[\NoDiscard] public function watch(): self { return new self( @@ -80,6 +83,7 @@ public function watch(): self * * @return Attempt */ + #[\NoDiscard] public function sink(Sequence $chunks): Attempt { return $this->sinkAttempts( @@ -92,6 +96,7 @@ public function sink(Sequence $chunks): Attempt * * @return Attempt */ + #[\NoDiscard] public function sinkAttempts(Sequence $chunks): Attempt { $stream = $this->stream;