From 6de216545b943c530378745d673992915b329be1 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 13:53:08 +0100 Subject: [PATCH 1/2] add NoDiscard attributes --- src/EnvironmentPath.php | 2 ++ src/Server.php | 9 +++++++++ src/Server/Cpu.php | 5 +++++ src/Server/Cpu/Cores.php | 2 ++ src/Server/Cpu/Percentage.php | 2 ++ src/Server/Disk.php | 2 ++ src/Server/Disk/Volume.php | 5 +++++ src/Server/Disk/Volume/MountPoint.php | 3 +++ src/Server/Disk/Volume/Usage.php | 2 ++ src/Server/LoadAverage.php | 3 +++ src/Server/Memory.php | 5 +++++ src/Server/Memory/Bytes.php | 2 ++ src/Server/Process.php | 6 ++++++ src/Server/Process/Command.php | 2 ++ src/Server/Process/Memory.php | 2 ++ src/Server/Process/Pid.php | 4 ++++ src/Server/Process/User.php | 1 + src/Server/Processes.php | 2 ++ src/ServerFactory.php | 1 + 19 files changed, 60 insertions(+) diff --git a/src/EnvironmentPath.php b/src/EnvironmentPath.php index a59edbb..9eceb10 100644 --- a/src/EnvironmentPath.php +++ b/src/EnvironmentPath.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/Server.php b/src/Server.php index c204219..43bd72b 100644 --- a/src/Server.php +++ b/src/Server.php @@ -27,6 +27,7 @@ private function __construct( ) { } + #[\NoDiscard] public static function osx( Clock $clock, Control $control, @@ -35,6 +36,7 @@ public static function osx( return new self(OSX::of($clock, $control, $path)); } + #[\NoDiscard] public static function linux( Clock $clock, Control $control, @@ -42,6 +44,7 @@ public static function linux( return new self(Linux::of($clock, $control)); } + #[\NoDiscard] public static function logger(self $server, LoggerInterface $logger): self { return new self(Logger::of( @@ -53,6 +56,7 @@ public static function logger(self $server, LoggerInterface $logger): self /** * @return Attempt */ + #[\NoDiscard] public function cpu(): Attempt { return $this->implementation->cpu(); @@ -61,11 +65,13 @@ public function cpu(): Attempt /** * @return Attempt */ + #[\NoDiscard] public function memory(): Attempt { return $this->implementation->memory(); } + #[\NoDiscard] public function processes(): Processes { return $this->implementation->processes(); @@ -74,16 +80,19 @@ public function processes(): Processes /** * @return Attempt */ + #[\NoDiscard] public function loadAverage(): Attempt { return $this->implementation->loadAverage(); } + #[\NoDiscard] public function disk(): Disk { return $this->implementation->disk(); } + #[\NoDiscard] public function tmp(): Path { return Path::of(\rtrim(\sys_get_temp_dir(), '/').'/'); diff --git a/src/Server/Cpu.php b/src/Server/Cpu.php index 9142bd0..cf184d2 100644 --- a/src/Server/Cpu.php +++ b/src/Server/Cpu.php @@ -34,26 +34,31 @@ public static function of( return new self($user, $system, $idle, $cores); } + #[\NoDiscard] public function user(): Percentage { return $this->user; } + #[\NoDiscard] public function system(): Percentage { return $this->system; } + #[\NoDiscard] public function idle(): Percentage { return $this->idle; } + #[\NoDiscard] public function cores(): Cores { return $this->cores; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Server/Cpu/Cores.php b/src/Server/Cpu/Cores.php index 029e7ab..57bfef3 100644 --- a/src/Server/Cpu/Cores.php +++ b/src/Server/Cpu/Cores.php @@ -30,11 +30,13 @@ public static function of(int $value): self /** * @return int<1, max> */ + #[\NoDiscard] public function toInt(): int { return $this->value; } + #[\NoDiscard] public function toString(): string { return (string) $this->value; diff --git a/src/Server/Cpu/Percentage.php b/src/Server/Cpu/Percentage.php index 869da66..2f6fd21 100644 --- a/src/Server/Cpu/Percentage.php +++ b/src/Server/Cpu/Percentage.php @@ -31,11 +31,13 @@ public static function maybe(float $value): Maybe return Maybe::just(new self($value)); } + #[\NoDiscard] public function toFloat(): float { return $this->value; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Server/Disk.php b/src/Server/Disk.php index 3265fc9..194113f 100644 --- a/src/Server/Disk.php +++ b/src/Server/Disk.php @@ -46,6 +46,7 @@ public static function logger(self $disk, LoggerInterface $logger): self /** * @return Sequence */ + #[\NoDiscard] public function volumes(): Sequence { return $this->implementation->volumes(); @@ -54,6 +55,7 @@ public function volumes(): Sequence /** * @return Maybe */ + #[\NoDiscard] public function get(MountPoint $point): Maybe { return $this->implementation->get($point); diff --git a/src/Server/Disk/Volume.php b/src/Server/Disk/Volume.php index e4f09cd..bf6ad1b 100644 --- a/src/Server/Disk/Volume.php +++ b/src/Server/Disk/Volume.php @@ -37,26 +37,31 @@ public static function of( return new self($mountPoint, $size, $available, $used, $usage); } + #[\NoDiscard] public function mountPoint(): MountPoint { return $this->mountPoint; } + #[\NoDiscard] public function size(): Bytes { return $this->size; } + #[\NoDiscard] public function available(): Bytes { return $this->available; } + #[\NoDiscard] public function used(): Bytes { return $this->used; } + #[\NoDiscard] public function usage(): Usage { return $this->usage; diff --git a/src/Server/Disk/Volume/MountPoint.php b/src/Server/Disk/Volume/MountPoint.php index b2bc9aa..6c07714 100644 --- a/src/Server/Disk/Volume/MountPoint.php +++ b/src/Server/Disk/Volume/MountPoint.php @@ -27,11 +27,13 @@ public static function of(string $value): self return new self($value); } + #[\NoDiscard] public function equals(self $point): bool { return $point->is($this->value); } + #[\NoDiscard] public function is(string $point): bool { return $this->value === $point; @@ -40,6 +42,7 @@ public function is(string $point): bool /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return $this->value; diff --git a/src/Server/Disk/Volume/Usage.php b/src/Server/Disk/Volume/Usage.php index 271e4d2..c3b7d29 100644 --- a/src/Server/Disk/Volume/Usage.php +++ b/src/Server/Disk/Volume/Usage.php @@ -31,11 +31,13 @@ public static function maybe(float $value): Maybe return Maybe::just(new self($value)); } + #[\NoDiscard] public function toFloat(): float { return $this->value; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Server/LoadAverage.php b/src/Server/LoadAverage.php index e9a99c6..18856ee 100644 --- a/src/Server/LoadAverage.php +++ b/src/Server/LoadAverage.php @@ -36,16 +36,19 @@ public static function maybe( return Maybe::just(new self($lastMinute, $lastFiveMinutes, $lastFifteenMinutes)); } + #[\NoDiscard] public function lastMinute(): float { return $this->lastMinute; } + #[\NoDiscard] public function lastFiveMinutes(): float { return $this->lastFiveMinutes; } + #[\NoDiscard] public function lastFifteenMinutes(): float { return $this->lastFifteenMinutes; diff --git a/src/Server/Memory.php b/src/Server/Memory.php index 0af8b99..6bf5abf 100644 --- a/src/Server/Memory.php +++ b/src/Server/Memory.php @@ -33,26 +33,31 @@ public static function of( return new self($total, $active, $free, $swap, $used); } + #[\NoDiscard] public function total(): Bytes { return $this->total; } + #[\NoDiscard] public function active(): Bytes { return $this->active; } + #[\NoDiscard] public function free(): Bytes { return $this->free; } + #[\NoDiscard] public function swap(): Bytes { return $this->swap; } + #[\NoDiscard] public function used(): Bytes { return $this->used; diff --git a/src/Server/Memory/Bytes.php b/src/Server/Memory/Bytes.php index 2273bf5..10fb202 100644 --- a/src/Server/Memory/Bytes.php +++ b/src/Server/Memory/Bytes.php @@ -44,11 +44,13 @@ public static function of(int $value): self /** * @return int<0, max> */ + #[\NoDiscard] public function toInt(): int { return $this->value; } + #[\NoDiscard] public function toString(): string { return Size::of($this->value)->toString(); diff --git a/src/Server/Process.php b/src/Server/Process.php index 38db37c..211766c 100644 --- a/src/Server/Process.php +++ b/src/Server/Process.php @@ -48,21 +48,25 @@ public static function of( return new self($pid, $user, $cpu, $memory, $start, $command); } + #[\NoDiscard] public function pid(): Pid { return $this->pid; } + #[\NoDiscard] public function user(): User { return $this->user; } + #[\NoDiscard] public function cpu(): Percentage { return $this->cpu; } + #[\NoDiscard] public function memory(): Memory { return $this->memory; @@ -71,11 +75,13 @@ public function memory(): Memory /** * @return Maybe */ + #[\NoDiscard] public function start(): Maybe { return $this->start; } + #[\NoDiscard] public function command(): Command { return $this->command; diff --git a/src/Server/Process/Command.php b/src/Server/Process/Command.php index e341991..24c0d31 100644 --- a/src/Server/Process/Command.php +++ b/src/Server/Process/Command.php @@ -32,6 +32,7 @@ public static function of(string $value): self return new self($value); } + #[\NoDiscard] public function matches(RegExp $pattern): bool { return $pattern->matches(Str::of($this->value)); @@ -40,6 +41,7 @@ public function matches(RegExp $pattern): bool /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return $this->value; diff --git a/src/Server/Process/Memory.php b/src/Server/Process/Memory.php index d68cf3b..7c431a5 100644 --- a/src/Server/Process/Memory.php +++ b/src/Server/Process/Memory.php @@ -31,11 +31,13 @@ public static function maybe(float $value): Maybe return Maybe::just(new self($value)); } + #[\NoDiscard] public function toFloat(): float { return $this->value; } + #[\NoDiscard] public function toString(): string { return \sprintf( diff --git a/src/Server/Process/Pid.php b/src/Server/Process/Pid.php index 96b4b03..9107deb 100644 --- a/src/Server/Process/Pid.php +++ b/src/Server/Process/Pid.php @@ -27,11 +27,13 @@ public static function of(int $value): self return new self($value); } + #[\NoDiscard] public function equals(self $pid): bool { return $pid->is($this->value); } + #[\NoDiscard] public function is(int $value): bool { return $this->value === $value; @@ -40,11 +42,13 @@ public function is(int $value): bool /** * @return int<1, max> */ + #[\NoDiscard] public function toInt(): int { return $this->value; } + #[\NoDiscard] public function toString(): string { return (string) $this->value; diff --git a/src/Server/Process/User.php b/src/Server/Process/User.php index 712a802..db7af58 100644 --- a/src/Server/Process/User.php +++ b/src/Server/Process/User.php @@ -30,6 +30,7 @@ public static function of(string $value): self /** * @return non-empty-string */ + #[\NoDiscard] public function toString(): string { return $this->value; diff --git a/src/Server/Processes.php b/src/Server/Processes.php index b28bb74..eec6b2a 100644 --- a/src/Server/Processes.php +++ b/src/Server/Processes.php @@ -54,6 +54,7 @@ public static function logger(self $processes, LoggerInterface $logger): self /** * @return Sequence */ + #[\NoDiscard] public function all(): Sequence { return $this->implementation->all(); @@ -62,6 +63,7 @@ public function all(): Sequence /** * @return Maybe */ + #[\NoDiscard] public function get(Pid $pid): Maybe { return $this->implementation->get($pid); diff --git a/src/ServerFactory.php b/src/ServerFactory.php index eb64076..367ac75 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -8,6 +8,7 @@ final class ServerFactory { + #[\NoDiscard] public static function build( Clock $clock, Control $control, From 4a03f86b9356f037b3c7b882e901a210044ebde1 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 13:55:52 +0100 Subject: [PATCH 2/2] discard unknown classes --- psalm.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/psalm.xml b/psalm.xml index 510148d..feccc34 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,4 +14,7 @@ + + +