From 7216705ad1f5e5c0593be97b0a7b7647677b0b6e Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 24 Aug 2025 13:39:11 +0200 Subject: [PATCH] use innmind/static-analysis --- composer.json | 3 +-- src/Client/Unix.php | 3 +++ src/Exception/DomainException.php | 2 +- src/IPC/Unix.php | 5 +++++ src/Message/ConnectionClose.php | 3 +++ src/Message/ConnectionCloseOk.php | 3 +++ src/Message/ConnectionStart.php | 3 +++ src/Message/ConnectionStartOk.php | 3 +++ src/Message/Generic.php | 3 +++ src/Message/Heartbeat.php | 3 +++ src/Message/MessageReceived.php | 3 +++ src/Process/Unix.php | 5 +++++ src/Protocol/Binary.php | 13 +++++++++++-- src/Server/Unix.php | 1 + 14 files changed, 48 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 9a73076..d8dcde3 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,7 @@ }, "require-dev": { "phpunit/phpunit": "~10.2", - "vimeo/psalm": "~5.15", - "nikic/php-parser": "^4.15.2", + "innmind/static-analysis": "^1.2.1", "innmind/black-box": "~5.5", "innmind/coding-standard": "~2.0" } diff --git a/src/Client/Unix.php b/src/Client/Unix.php index dc7a263..988b3bb 100644 --- a/src/Client/Unix.php +++ b/src/Client/Unix.php @@ -22,6 +22,7 @@ public function __construct(Connection $connection, Protocol $protocol) $this->protocol = $protocol; } + #[\Override] public function send(Message $message): Maybe { if ($this->connection->closed()) { @@ -37,6 +38,7 @@ public function send(Message $message): Maybe ->map(fn() => $this); } + #[\Override] public function read(): Maybe { /** @var Maybe */ @@ -46,6 +48,7 @@ public function read(): Maybe ->map(fn($message) => [$this, $message]); } + #[\Override] public function close(): Maybe { return $this->connection->close()->maybe(); diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php index 01c3a95..ec9c06e 100644 --- a/src/Exception/DomainException.php +++ b/src/Exception/DomainException.php @@ -3,6 +3,6 @@ namespace Innmind\IPC\Exception; -class DomainException extends \DomainException implements Exception +final class DomainException extends \DomainException implements Exception { } diff --git a/src/IPC/Unix.php b/src/IPC/Unix.php index 0d9d2d4..93bc6b9 100644 --- a/src/IPC/Unix.php +++ b/src/IPC/Unix.php @@ -63,6 +63,7 @@ public function __construct( $this->heartbeat = $heartbeat; } + #[\Override] public function processes(): Set { return $this @@ -77,6 +78,7 @@ public function processes(): Set ->toSet(); } + #[\Override] public function get(Process\Name $name): Maybe { if (!$this->exist($name)) { @@ -94,11 +96,13 @@ public function get(Process\Name $name): Maybe ); } + #[\Override] public function exist(Process\Name $name): bool { return $this->filesystem->contains(FileName::of("{$name->toString()}.sock")); } + #[\Override] public function wait(Process\Name $name, ?ElapsedPeriod $timeout = null): Maybe { $start = $this->clock->now(); @@ -118,6 +122,7 @@ public function wait(Process\Name $name, ?ElapsedPeriod $timeout = null): Maybe return $this->get($name); } + #[\Override] public function listen(Process\Name $self, ?ElapsedPeriod $timeout = null): Server { return new Server\Unix( diff --git a/src/Message/ConnectionClose.php b/src/Message/ConnectionClose.php index 786bd42..9dfd104 100644 --- a/src/Message/ConnectionClose.php +++ b/src/Message/ConnectionClose.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:connection.close'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/ConnectionCloseOk.php b/src/Message/ConnectionCloseOk.php index 1c9a56d..60fc566 100644 --- a/src/Message/ConnectionCloseOk.php +++ b/src/Message/ConnectionCloseOk.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:connection.close-ok'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/ConnectionStart.php b/src/Message/ConnectionStart.php index 9359e5e..03d12a0 100644 --- a/src/Message/ConnectionStart.php +++ b/src/Message/ConnectionStart.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:connection.start'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/ConnectionStartOk.php b/src/Message/ConnectionStartOk.php index 8bf249b..e709a88 100644 --- a/src/Message/ConnectionStartOk.php +++ b/src/Message/ConnectionStartOk.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:connection.start-ok'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/Generic.php b/src/Message/Generic.php index 707e417..7063007 100644 --- a/src/Message/Generic.php +++ b/src/Message/Generic.php @@ -29,16 +29,19 @@ public static function of(string $mediaType, string $content): self ); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/Heartbeat.php b/src/Message/Heartbeat.php index 93542a9..bec5435 100644 --- a/src/Message/Heartbeat.php +++ b/src/Message/Heartbeat.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:heartbeat'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Message/MessageReceived.php b/src/Message/MessageReceived.php index 87130e1..1f74bde 100644 --- a/src/Message/MessageReceived.php +++ b/src/Message/MessageReceived.php @@ -21,16 +21,19 @@ public function __construct() $this->content = Str::of('innmind/ipc:message.received'); } + #[\Override] public function mediaType(): MediaType { return $this->mediaType; } + #[\Override] public function content(): Str { return $this->content; } + #[\Override] public function equals(Message $message): bool { return $this->mediaType->toString() === $message->mediaType()->toString() && diff --git a/src/Process/Unix.php b/src/Process/Unix.php index 2976945..b6014ad 100644 --- a/src/Process/Unix.php +++ b/src/Process/Unix.php @@ -87,11 +87,13 @@ public static function of( ->flatMap(static fn($self) => $self->open()); } + #[\Override] public function name(): Name { return $this->name; } + #[\Override] public function send(Sequence $messages): Maybe { /** @var Maybe */ @@ -101,6 +103,7 @@ public function send(Sequence $messages): Maybe ); } + #[\Override] public function wait(?ElapsedPeriod $timeout = null): Maybe { do { @@ -160,6 +163,7 @@ public function wait(?ElapsedPeriod $timeout = null): Maybe }); } + #[\Override] public function close(): Maybe { if ($this->closed()) { @@ -182,6 +186,7 @@ public function close(): Maybe ); } + #[\Override] public function closed(): bool { return $this->closed || $this->socket->closed(); diff --git a/src/Protocol/Binary.php b/src/Protocol/Binary.php index e174129..7124475 100644 --- a/src/Protocol/Binary.php +++ b/src/Protocol/Binary.php @@ -17,6 +17,7 @@ final class Binary implements Protocol { + #[\Override] public function encode(Message $message): Str { $content = $message->content()->toEncoding(Str\Encoding::ascii); @@ -35,6 +36,7 @@ public function encode(Message $message): Str ); } + #[\Override] public function decode(Readable $stream): Maybe { /** @var Maybe */ @@ -42,7 +44,10 @@ public function decode(Readable $stream): Maybe ->read(2) ->filter(static fn($length) => !$length->empty()) ->map(static function($length): int { - /** @var positive-int $mediaTypeLength */ + /** + * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate + * @var positive-int $mediaTypeLength + */ [, $mediaTypeLength] = \unpack('n', $length->toString()); return $mediaTypeLength; @@ -53,7 +58,10 @@ public function decode(Readable $stream): Maybe return $stream ->read(4) ->map(static function($length): int { - /** @var positive-int $contentLength */ + /** + * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate + * @var positive-int $contentLength + */ [, $contentLength] = \unpack('N', $length->toString()); return $contentLength; @@ -67,6 +75,7 @@ public function decode(Readable $stream): Maybe fn($parsed) => $stream ->read(1) ->map(static function($end): mixed { + /** @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate */ [, $end] = \unpack('C', $end->toString()); return $end; diff --git a/src/Server/Unix.php b/src/Server/Unix.php index 0397197..e21b2e2 100644 --- a/src/Server/Unix.php +++ b/src/Server/Unix.php @@ -60,6 +60,7 @@ public function __construct( * * @return Either */ + #[\Override] public function __invoke(mixed $carry, callable $listen): Either { $iteration = $this