From 2fd76ef67ca7e1f732151f8c0f8ad168089b22d8 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 15 Feb 2026 16:46:45 +0100 Subject: [PATCH] add NoDiscard attributes --- psalm.xml | 3 +++ src/Manager.php | 3 +++ src/Manager/Native.php | 1 + src/Session.php | 8 ++++++++ src/Session/Id.php | 2 ++ src/Session/Name.php | 2 ++ 6 files changed, 19 insertions(+) diff --git a/psalm.xml b/psalm.xml index 510148d..feccc34 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,4 +14,7 @@ + + + diff --git a/src/Manager.php b/src/Manager.php index fee4b87..7774cf0 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -14,15 +14,18 @@ interface Manager /** * @return Maybe */ + #[\NoDiscard] public function start(ServerRequest $request): Maybe; /** * @return Maybe */ + #[\NoDiscard] public function save(Session $session): Maybe; /** * @return Maybe */ + #[\NoDiscard] public function close(Session $session): Maybe; } diff --git a/src/Manager/Native.php b/src/Manager/Native.php index 57e15d1..b379af2 100644 --- a/src/Manager/Native.php +++ b/src/Manager/Native.php @@ -32,6 +32,7 @@ private function __construct(?Path $save = null) } } + #[\NoDiscard] public static function of(?Path $save = null): self { return new self($save); diff --git a/src/Session.php b/src/Session.php index e221d04..302a812 100644 --- a/src/Session.php +++ b/src/Session.php @@ -38,16 +38,19 @@ private function __construct(Id $id, Name $name, Map $values) * * @param Map $values */ + #[\NoDiscard] public static function of(Id $id, Name $name, Map $values): self { return new self($id, $name, $values); } + #[\NoDiscard] public function id(): Id { return $this->id; } + #[\NoDiscard] public function name(): Name { return $this->name; @@ -58,6 +61,7 @@ public function name(): Name * * @throws LogicException */ + #[\NoDiscard] public function get(string $key): mixed { return $this->maybe($key)->match( @@ -69,16 +73,19 @@ public function get(string $key): mixed /** * @return Maybe */ + #[\NoDiscard] public function maybe(string $key): Maybe { return $this->values->get($key); } + #[\NoDiscard] public function contains(string $key): bool { return $this->values->contains($key); } + #[\NoDiscard] public function with(string $key, mixed $value): self { return new self( @@ -95,6 +102,7 @@ public function with(string $key, mixed $value): self * * @return Map */ + #[\NoDiscard] public function values(): Map { return $this->values; diff --git a/src/Session/Id.php b/src/Session/Id.php index 9da2d6b..c3e6cfd 100644 --- a/src/Session/Id.php +++ b/src/Session/Id.php @@ -25,6 +25,7 @@ private function __construct(string $value) * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $value): Maybe { return Maybe::just(Str::of($value)) @@ -32,6 +33,7 @@ public static function maybe(string $value): Maybe ->map(static fn($value) => new self($value->toString())); } + #[\NoDiscard] public function toString(): string { return $this->value; diff --git a/src/Session/Name.php b/src/Session/Name.php index 19b6569..4067c26 100644 --- a/src/Session/Name.php +++ b/src/Session/Name.php @@ -26,6 +26,7 @@ private function __construct(string $value) * * @return Maybe */ + #[\NoDiscard] public static function maybe(string $value): Maybe { return Maybe::just(Str::of($value)) @@ -33,6 +34,7 @@ public static function maybe(string $value): Maybe ->map(static fn($value) => new self($value->toString())); } + #[\NoDiscard] public function toString(): string { return $this->value;