Skip to content

Commit 66f274f

Browse files
committed
Fix or suppress Psalm 6 issues
1 parent 372e47b commit 66f274f

11 files changed

Lines changed: 43 additions & 10 deletions

File tree

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,30 @@
1414
</projectFiles>
1515

1616
<issueHandlers>
17+
<PossiblyUnusedMethod>
18+
<errorLevel type="suppress">
19+
<directory name="src"/>
20+
</errorLevel>
21+
</PossiblyUnusedMethod>
22+
23+
<PossiblyUnusedReturnValue>
24+
<errorLevel type="suppress">
25+
<directory name="src"/>
26+
</errorLevel>
27+
</PossiblyUnusedReturnValue>
28+
1729
<RiskyTruthyFalsyComparison>
1830
<errorLevel type="suppress">
1931
<directory name="src"/>
2032
</errorLevel>
2133
</RiskyTruthyFalsyComparison>
2234

35+
<UnusedClass>
36+
<errorLevel type="suppress">
37+
<directory name="src"/>
38+
</errorLevel>
39+
</UnusedClass>
40+
2341
<UnsupportedPropertyReferenceUsage>
2442
<errorLevel type="suppress">
2543
<directory name="src"/>

src/Command/Boundary/ScoreBoundary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class ScoreBoundary
66
{
77
public static function exclusive(float $value): self
88
{
9-
return new self('(' . $value);
9+
return new self(sprintf('(%.5f', $value));
1010
}
1111

1212
public static function inclusive(float $value): self

src/Command/RedisMap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public function scan(?string $pattern = null, ?int $count = null): \Traversable
157157
$query[] = $count;
158158
}
159159

160-
/** @var list<string> $keys */
161160
[$cursor, $keys] = $this->client->execute('HSCAN', ...$query);
162161

163162
$count = \count($keys);

src/Command/RedisSortedSet.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ public function scan(?string $pattern = null, ?int $count = null): \Traversable
218218
$query[] = $count;
219219
}
220220

221-
/** @var list<string> $keys */
222221
[$cursor, $keys] = $this->client->execute('ZSCAN', ...$query);
223222

224223
$count = \count($keys);

src/Connection/ReconnectingRedisLink.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,12 @@ private function run(): void
100100
$connection->unreference();
101101

102102
try {
103-
foreach ($queue as [$deferred, $command, $parameters]) {
103+
foreach ($queue as [, $command, $parameters]) {
104104
$connection->reference();
105105
$connection->send($command, ...$parameters);
106106
}
107107

108108
while ($response = $connection->receive()) {
109-
/** @var DeferredFuture $deferred */
110109
[$deferred] = $queue->shift();
111110
if ($queue->isEmpty()) {
112111
$connection->unreference();
@@ -124,7 +123,6 @@ private function run(): void
124123
$exception = new RedisConnectionException($exception->getMessage(), 0, $exception);
125124

126125
while (!$queue->isEmpty()) {
127-
/** @var DeferredFuture $deferred */
128126
[$deferred] = $queue->shift();
129127
$deferred->error($exception);
130128
}

src/Protocol/RedisError.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function unwrap(): never
2121
public function getKind(): ?string
2222
{
2323
$prefix = \strtok($this->message, ' ');
24+
\assert(is_string($prefix)); // For Psalm.
2425

2526
// This is just a convention of Redis server, not part of the protocol
2627
if ($prefix === \strtoupper($prefix)) {

src/Protocol/RespParser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @psalm-type ParserGeneratorType = \Generator<int, int|string, string, RedisResponse>
11+
*
12+
* @psalm-suppress InvalidIterator
1113
*/
1214
final class RespParser
1315
{

src/RedisClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ public function countBits(string $key, ?int $start = null, ?int $end = null): in
272272
$cmd[] = $start;
273273
$cmd[] = $end;
274274
} elseif (isset($start) || isset($end)) {
275-
throw new \Error('Start and end must both be set or unset in countBits(), got start = ' . $start . ' and end = ' . $end);
275+
throw new \Error(sprintf(
276+
'Start and end must both be set or unset in countBits(), got start = %s and end = %s',
277+
$start ?? 'null',
278+
$end ?? 'null',
279+
));
276280
}
277281

278282
return $this->execute('bitcount', ...$cmd);

src/RedisConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private function applyUri(string $uri): void
9797
try {
9898
$uri = Uri::new($uri);
9999
} catch (\Exception) {
100+
/** @psalm-suppress ImplicitToStringCast */
100101
throw new RedisException('Invalid redis configuration URI: ' . $uri);
101102
}
102103

src/Sync/RedisMutex.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ public function acquire(string $key): Lock
165165
$result = $this->redis->eval(
166166
self::LOCK,
167167
["{$prefix}lock:{$key}", "{$prefix}lock-queue:{$key}"],
168-
[$token, $this->options->getLockExpiration() * 1000, ($this->options->getLockExpiration() + $this->options->getLockTimeout()) * 1000]
168+
[
169+
$token,
170+
$this->options->getLockExpiration() * 1000.0,
171+
($this->options->getLockExpiration() + $this->options->getLockTimeout()) * 1000.0,
172+
],
169173
);
170174

171175
if ($result < 1) {
@@ -176,7 +180,11 @@ public function acquire(string $key): Lock
176180
$this->redis->getList("{$prefix}lock-queue:{$key}")->remove($token);
177181
$this->unlock($key, $token);
178182

179-
throw new RedisMutexException('Failed to acquire lock for ' . $key . ' within ' . $this->options->getLockTimeout() * 1000 . ' ms');
183+
throw new RedisMutexException(sprintf(
184+
'Failed to acquire lock for %s within %.5f ms',
185+
$key,
186+
$this->options->getLockTimeout() * 1000.0,
187+
));
180188
}
181189

182190
// A negative integer as reply means we're still in the queue and indicates the queue position.
@@ -265,7 +273,7 @@ static function () use (&$locks, $options, $redis, $logger): void {
265273
\assert(!empty($locks));
266274

267275
$keys = [];
268-
$arguments = [$options->getLockExpiration() * 1000];
276+
$arguments = [$options->getLockExpiration() * 1000.0];
269277

270278
$prefix = $options->getKeyPrefix();
271279

0 commit comments

Comments
 (0)