Skip to content

Commit 5e37d23

Browse files
author
Stepan Zolotarev
committed
CS fix
1 parent 672faa9 commit 5e37d23

File tree

5 files changed

+16
-28
lines changed

5 files changed

+16
-28
lines changed

src/InMemory/InMemoryMutexService.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Amp\Promise;
1616
use ServiceBus\Mutex\MutexService;
17+
1718
use function Amp\call;
1819
use function Amp\delay;
1920

@@ -27,22 +28,17 @@ final class InMemoryMutexService implements MutexService
2728
public function withLock(string $id, callable $code): Promise
2829
{
2930
return call(
30-
static function () use ($id, $code): \Generator
31-
{
32-
try
33-
{
34-
while (InMemoryMutexStorage::instance()->has($id))
35-
{
31+
static function () use ($id, $code): \Generator {
32+
try {
33+
while (InMemoryMutexStorage::instance()->has($id)) {
3634
yield delay(self::LATENCY_TIMEOUT);
3735
}
3836

3937
InMemoryMutexStorage::instance()->lock($id);
4038

4139
/** @psalm-suppress PossiblyInvalidArgument */
4240
yield call($code);
43-
}
44-
finally
45-
{
41+
} finally {
4642
InMemoryMutexStorage::instance()->unlock($id);
4743
}
4844
}

src/InMemory/InMemoryMutexStorage.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ final class InMemoryMutexStorage
2929

3030
public static function instance(): self
3131
{
32-
if (self::$instance === null)
33-
{
32+
if (self::$instance === null) {
3433
self::$instance = new self();
3534
}
3635

src/Redis/RedisMutexService.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Amp\Redis\Redis;
1717
use Amp\Redis\SetOptions;
1818
use ServiceBus\Mutex\MutexService;
19+
1920
use function Amp\call;
2021
use function Amp\delay;
2122

@@ -44,12 +45,9 @@ public function __construct(Redis $client, int $lockLifetime = self::DEFAULT_LOC
4445
public function withLock(string $id, callable $code): Promise
4546
{
4647
return call(
47-
function () use ($id, $code): \Generator
48-
{
49-
try
50-
{
51-
while (!yield $this->client->set($id, 'lock', $this->lockOptions))
52-
{
48+
function () use ($id, $code): \Generator {
49+
try {
50+
while (!yield $this->client->set($id, 'lock', $this->lockOptions)) {
5351
yield delay(self::LATENCY_TIMEOUT);
5452
}
5553

@@ -58,9 +56,7 @@ function () use ($id, $code): \Generator
5856
* @phpstan-ignore generator.valueType
5957
*/
6058
yield call($code);
61-
}
62-
finally
63-
{
59+
} finally {
6460
yield $this->client->delete($id);
6561
}
6662
}

tests/InMemory/InMemoryMutexServiceTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ protected function tearDown(): void
3636
public function acquire(): void
3737
{
3838
Loop::run(
39-
static function (): \Generator
40-
{
39+
static function (): \Generator {
4140
$id = \sha1(uniqid("test", true));
4241
$mutexService = new InMemoryMutexService();
4342

4443
yield $mutexService->withLock(
4544
$id,
46-
static function () use ($id): void
47-
{
45+
static function () use ($id): void {
4846
self::assertTrue(InMemoryMutexStorage::instance()->has($id));
4947
}
5048
);

tests/Redis/RedisMutexServiceTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Amp\Redis\RemoteExecutor;
2222
use PHPUnit\Framework\TestCase;
2323
use ServiceBus\Mutex\Redis\RedisMutexService;
24+
2425
use function Amp\call;
2526

2627
final class RedisMutexServiceTest extends TestCase
@@ -54,15 +55,13 @@ protected function tearDown(): void
5455
public function acquire(): void
5556
{
5657
Loop::run(
57-
function (): \Generator
58-
{
58+
function (): \Generator {
5959
$id = \sha1(uniqid("test", true));
6060
$mutexService = new RedisMutexService($this->client);
6161

6262
yield $mutexService->withLock(
6363
$id,
64-
function () use ($id): \Generator
65-
{
64+
function () use ($id): \Generator {
6665
self::assertTrue(yield $this->client->has($id));
6766
}
6867
);

0 commit comments

Comments
 (0)