From be399545ea729ab6091b3d1f5ec2be250cbb9fcb Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 9 Oct 2026 22:59:36 +0400 Subject: [PATCH] refactor: mark overriding methods with `#[\Override]` Psalm now checks `MissingOverrideAttribute` instead of suppressing it. The attribute is harmless on PHP 8.2, which does not validate it. `ClassMustBeFinal` stays suppressed because making public classes final would break BC. The `@psalm-suppress` on `Logger::log()` matched no issue and is dropped. Assisted-By: Claude Opus 5.5 --- psalm.xml | 1 - src/Environment.php | 3 +++ src/Informer/Workers.php | 1 + src/Logger.php | 4 +--- src/Worker.php | 7 +++++++ tests/Unit/Stub/TestRelay.php | 3 +++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/psalm.xml b/psalm.xml index 71c6520..b8ef5de 100644 --- a/psalm.xml +++ b/psalm.xml @@ -15,7 +15,6 @@ - diff --git a/src/Environment.php b/src/Environment.php index 9c6c907..8a44aad 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -33,16 +33,19 @@ public static function fromGlobals(): self return new self($env); } + #[\Override] public function getMode(): string { return $this->get('RR_MODE'); } + #[\Override] public function getRelayAddress(): string { return $this->get('RR_RELAY', 'pipes'); } + #[\Override] public function getRPCAddress(): string { return $this->get('RR_RPC', 'tcp://127.0.0.1:6001'); diff --git a/src/Informer/Workers.php b/src/Informer/Workers.php index 96e24e5..2b25226 100644 --- a/src/Informer/Workers.php +++ b/src/Informer/Workers.php @@ -21,6 +21,7 @@ public function getWorkers(): array return $this->workers; } + #[\Override] public function count(): int { return \count($this->workers); diff --git a/src/Logger.php b/src/Logger.php index dd477f1..8c02dca 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -11,9 +11,7 @@ class Logger implements LoggerInterface { use LoggerTrait; - /** - * @psalm-suppress RedundantConditionGivenDocblockType - */ + #[\Override] public function log(mixed $level, string|\Stringable $message, array $context = []): void { \assert(\is_scalar($level), 'Invalid log level type'); diff --git a/src/Worker.php b/src/Worker.php index 099cffb..70640f4 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -90,6 +90,7 @@ public function getLogger(): LoggerInterface return $this->logger; } + #[\Override] public function waitPayload(): ?Payload { while (true) { @@ -118,6 +119,7 @@ public function waitPayload(): ?Payload } } + #[\Override] public function withStreamMode(): static { $clone = clone $this; @@ -133,12 +135,14 @@ public function withStreamMode(): static * Can be {@see Frame::CODEC_PROTO} for Protocol Buffers or {@see Frame::CODEC_JSON} for JSON. * This parameter will be removed in v4.0 and {@see Frame::CODEC_PROTO} will be used by default. */ + #[\Override] public function respond(Payload $payload, ?int $codec = null): void { $this->streamMode and ++$this->framesSent; $this->send($payload->body, $payload->header, $payload->eos, $codec); } + #[\Override] public function error(string $error): void { $frame = new Frame($error, [], Frame::ERROR); @@ -146,16 +150,19 @@ public function error(string $error): void $this->sendFrame($frame); } + #[\Override] public function stop(): void { $this->send('', $this->encode(['stop' => true])); } + #[\Override] public function hasPayload(?string $class = null): bool { return $this->findPayload($class) !== null; } + #[\Override] public function getPayload(?string $class = null): ?Payload { $pos = $this->findPayload($class); diff --git a/tests/Unit/Stub/TestRelay.php b/tests/Unit/Stub/TestRelay.php index 57c5e06..cfbb52b 100644 --- a/tests/Unit/Stub/TestRelay.php +++ b/tests/Unit/Stub/TestRelay.php @@ -54,6 +54,7 @@ public function getReceivedBody(): string => \substr($frame->payload, $frame->options[0] ?? 0), $this->received)); } + #[\Override] public function waitFrame(): Frame { if ($this->frames === []) { @@ -63,11 +64,13 @@ public function waitFrame(): Frame return \array_shift($this->frames); } + #[\Override] public function send(Frame $frame): void { $this->received[] = $frame; } + #[\Override] public function hasFrame(): bool { return $this->frames !== [];