Skip to content

Commit 6e122dd

Browse files
committed
Fix or suppress Psalm 6 issues
1 parent bbcf02a commit 6e122dd

8 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎src/Driver/BlockingFile.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ public function __destruct()
6262
/**
6363
* Returns the currently active lock mode, or null if the file is not locked.
6464
*/
65+
#[\Override]
6566
public function getLockType(): ?LockType
6667
{
6768
return $this->lockType;
6869
}
6970

71+
#[\Override]
7072
public function lock(LockType $type, ?Cancellation $cancellation = null): void
7173
{
7274
Internal\lock($this->path, $this->getFileHandle(), $type, $cancellation);
7375
$this->lockType = $type;
7476
}
7577

78+
#[\Override]
7679
public function tryLock(LockType $type): bool
7780
{
7881
$locked = Internal\tryLock($this->path, $this->getFileHandle(), $type);
@@ -83,6 +86,7 @@ public function tryLock(LockType $type): bool
8386
return $locked;
8487
}
8588

89+
#[\Override]
8690
public function unlock(): void
8791
{
8892
Internal\unlock($this->path, $this->getFileHandle());

‎src/Driver/EioFile.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ public function __construct(Internal\EioPoll $poll, int $fh, string $path, strin
3030

3131
$this->poll = $poll;
3232
$this->fh = $fh;
33-
$this->fd = \fopen('php://fd/' . $this->fh, 'r');
33+
$fd = \fopen('php://fd/' . $this->fh, 'r');
34+
if ($fd === false) {
35+
throw new StreamException("Failed to open file descriptor " . $this->fh);
36+
}
37+
$this->fd = $fd;
3438

3539
$this->onClose = new DeferredFuture;
3640
}
3741

42+
#[\Override]
3843
protected function getFileHandle()
3944
{
4045
if (!\is_resource($this->fd)) {

‎src/Driver/ParallelFile.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ public function eof(): bool
157157
return $this->pendingWrites === 0 && $this->size <= $this->position;
158158
}
159159

160+
#[\Override]
160161
public function lock(LockType $type, ?Cancellation $cancellation = null): void
161162
{
162163
$this->flock('lock', $type, $cancellation);
163164
$this->lockType = $type;
164165
}
165166

167+
#[\Override]
166168
public function tryLock(LockType $type): bool
167169
{
168170
$locked = $this->flock('try-lock', $type);
@@ -173,12 +175,14 @@ public function tryLock(LockType $type): bool
173175
return $locked;
174176
}
175177

178+
#[\Override]
176179
public function unlock(): void
177180
{
178181
$this->flock('unlock');
179182
$this->lockType = null;
180183
}
181184

185+
#[\Override]
182186
public function getLockType(): ?LockType
183187
{
184188
return $this->lockType;

‎src/Driver/StatusCachingFile.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,25 @@ public function end(): void
5757
}
5858
}
5959

60+
#[\Override]
6061
public function lock(LockType $type, ?Cancellation $cancellation = null): void
6162
{
6263
$this->file->lock($type, $cancellation);
6364
}
6465

66+
#[\Override]
6567
public function tryLock(LockType $type): bool
6668
{
6769
return $this->file->tryLock($type);
6870
}
6971

72+
#[\Override]
7073
public function unlock(): void
7174
{
7275
$this->file->unlock();
7376
}
7477

78+
#[\Override]
7579
public function getLockType(): ?LockType
7680
{
7781
return $this->file->getLockType();

‎src/Driver/UvFile.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function __construct(
4646
$this->onClose = new DeferredFuture;
4747
}
4848

49+
#[\Override]
4950
protected function getFileHandle()
5051
{
5152
if ($this->closing) {

‎src/Internal/FileTask.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function run(Channel $channel, Cancellation $cancellation): mixed
120120
throw new \Error("Invalid lock action - " . $action);
121121
}
122122

123+
/** @psalm-suppress UnevaluatedCode */
123124
return false; // CS fixer fails without this return.
124125

125126
default:

‎src/Internal/QueuedWritesFile.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,14 @@ public function truncate(int $size): void
135135
*/
136136
abstract protected function getFileHandle();
137137

138+
#[\Override]
138139
public function lock(LockType $type, ?Cancellation $cancellation = null): void
139140
{
140141
lock($this->path, $this->getFileHandle(), $type, $cancellation);
141142
$this->lockType = $type;
142143
}
143144

145+
#[\Override]
144146
public function tryLock(LockType $type): bool
145147
{
146148
$locked = tryLock($this->path, $this->getFileHandle(), $type);
@@ -151,12 +153,14 @@ public function tryLock(LockType $type): bool
151153
return $locked;
152154
}
153155

156+
#[\Override]
154157
public function unlock(): void
155158
{
156159
unlock($this->path, $this->getFileHandle());
157160
$this->lockType = null;
158161
}
159162

163+
#[\Override]
160164
public function getLockType(): ?LockType
161165
{
162166
return $this->lockType;

‎src/Internal/functions.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function lock(string $path, $handle, LockType $type, ?Cancellation $cancellation
2121
return;
2222
}
2323

24-
// Exponential back-off with a maximum delay of 1 second.
24+
/**
25+
* Exponential back-off with a maximum delay of 1 second.
26+
* @psalm-suppress InvalidOperand
27+
*/
2528
delay(\min(1, 0.01 * (2 ** $attempt)), cancellation: $cancellation);
2629
}
2730
}

0 commit comments

Comments
 (0)