Skip to content

Commit 38de448

Browse files
committed
fix psalm common
1 parent ad9b8c5 commit 38de448

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Common/GeneratorHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function getReturnFromGenerator(Generator $generator, float $timeo
3434
{
3535
$start = microtime(true);
3636
while ($generator->valid()) {
37-
if ($timeout) {
37+
if ($timeout !== null) {
3838
self::guardTiming($start, $timeout);
3939
}
4040
$generator->next();

src/Common/SysVSemaphore.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@
2929

3030
class SysVSemaphore implements SemaphoreInterface
3131
{
32-
/**
33-
* @param resource $semaphore
34-
*/
3532
private function __construct(
36-
private $semaphore
33+
private readonly \SysvSemaphore $semaphore
3734
) {}
3835

3936
public static function create(string $key, int $max): self
4037
{
4138
$key = hash('sha512', $key, true);
4239
$key = substr($key, 0, 8);
4340

44-
return new self(sem_get(hexdec($key), $max));
41+
if (!function_exists('sem_get')) {
42+
throw new RuntimeException('Can only create a semaphore if the sysv extension is installed');
43+
}
44+
45+
$semaphore = sem_get(hexdec($key), $max);
46+
if ($semaphore === false) {
47+
throw new RuntimeException('Could not create semaphore');
48+
}
49+
50+
return new self($semaphore);
4551
}
4652

4753
public function wait(): Generator

0 commit comments

Comments
 (0)