From 6ea33269cb4e08eee7d81ec34c18e0f764655350 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 9 Oct 2026 23:58:02 +0400 Subject: [PATCH] refactor: mark overriding methods with `#[\Override]` Psalm now checks `MissingOverrideAttribute` and `InvalidOperand` instead of suppressing them; the attribute is harmless on PHP 8.2. The TTL is converted to float before scaling, which keeps the result for every realistic TTL. The redundant `round()` on the integral DateInterval product is gone, so Infection no longer reports it as equivalent escaped mutants. Assisted-By: Claude Opus 5.5 --- psalm.xml | 10 ---------- src/Lock.php | 10 ++++++++-- src/UuidLockIdGenerator.php | 1 + 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/psalm.xml b/psalm.xml index e1f086b..7e98f69 100644 --- a/psalm.xml +++ b/psalm.xml @@ -13,14 +13,4 @@ - - - - - - - - - - diff --git a/src/Lock.php b/src/Lock.php index bd03f6c..b3a9cff 100644 --- a/src/Lock.php +++ b/src/Lock.php @@ -41,6 +41,7 @@ public function __construct( * * @throws \InvalidArgumentException If ttl is negative. */ + #[\Override] public function lock( string $resource, ?string $id = null, @@ -78,6 +79,7 @@ public function lock( * * @throws \InvalidArgumentException If ttl is negative. */ + #[\Override] public function lockRead( string $resource, ?string $id = null, @@ -105,6 +107,7 @@ public function lockRead( * @param non-empty-string $id Lock ID from lock or lockRead method. * @return bool Returns true if the lock was released successfully, false otherwise. */ + #[\Override] public function release(string $resource, string $id): bool { $request = new Request(); @@ -126,6 +129,7 @@ public function release(string $resource, string $id): bool * @param non-empty-string $resource The name of the resource to be unlocked * @return bool Returns true if all locks were released successfully, false otherwise */ + #[\Override] public function forceRelease(string $resource): bool { $request = new Request(); @@ -145,6 +149,7 @@ public function forceRelease(string $resource): bool * @param string|null $id Lock ID from lock or lockRead method. * @return bool Returns true if the resource is locked, false otherwise. */ + #[\Override] public function exists(string $resource, ?string $id = null): bool { $request = new Request(); @@ -166,6 +171,7 @@ public function exists(string $resource, ?string $id = null): bool * * @throws \InvalidArgumentException If ttl is negative. */ + #[\Override] public function updateTTL(string $resource, string $id, int|float|\DateInterval $ttl): bool { $request = new Request(); @@ -181,12 +187,12 @@ public function updateTTL(string $resource, string $id, int|float|\DateInterval private function convertTimeToMicroseconds(int|float|\DateInterval $ttl): int { if ($ttl instanceof \DateInterval) { - return (int) \round((int) $ttl->format('%s') * 1_000_000); + return (int) $ttl->format('%s') * 1_000_000; } \assert($ttl >= 0, 'TTL must be positive'); - return (int) \round($ttl * 1_000_000); + return (int) \round((float) $ttl * 1_000_000.0); } /** diff --git a/src/UuidLockIdGenerator.php b/src/UuidLockIdGenerator.php index 8ee41f7..e8577c5 100644 --- a/src/UuidLockIdGenerator.php +++ b/src/UuidLockIdGenerator.php @@ -13,6 +13,7 @@ public function __construct( private readonly UuidFactoryInterface $factory = new UuidFactory(), ) {} + #[\Override] public function generate(): string { return $this->factory->uuid4()->toString();