Skip to content

Commit 2b9a218

Browse files
committed
swoole fixes
1 parent fba5b68 commit 2b9a218

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"phpunit/phpunit": "^9.5",
4444
"rector/rector": "^0.14",
4545
"symplify/easy-coding-standard": "^11.1",
46-
"vimeo/psalm": "^4.26"
46+
"vimeo/psalm": "^4.27"
4747
},
4848
"suggest": {
4949
"bavix/laravel-wallet-swap": "Addition to the laravel-wallet library for quick setting of exchange rates",

phpstan-baseline.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ parameters:
3737

3838
-
3939
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateService\\:\\:get\\(\\) should return string\\|null but returns mixed\\.$#"
40-
count: 1
40+
count: 2
4141
path: src/Internal/Service/StateService.php
4242

4343
-
44-
message: "#^Trying to invoke mixed but it's not a callable\\.$#"
44+
message: "#^Parameter \\#2 \\$callback of method Illuminate\\\\Contracts\\\\Cache\\\\Repository\\:\\:rememberForever\\(\\) expects Closure, mixed given\\.$#"
4545
count: 1
4646
path: src/Internal/Service/StateService.php
4747

src/Internal/Service/DatabaseService.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,42 @@ public function transaction(callable $callback): mixed
4141
);
4242
}
4343

44+
if ($level > 0) {
45+
return $callback();
46+
}
47+
4448
$this->init = true;
4549

4650
try {
47-
if ($level > 0) {
48-
return $callback();
49-
}
50-
5151
$this->regulatorService->purge();
5252

5353
return $this->connection->transaction(function () use ($callback) {
5454
$result = $callback();
5555
$this->init = false;
5656

57-
if ($result === false || (is_countable($result) && count($result) === 0)) {
58-
$this->regulatorService->purge();
59-
} else {
60-
$this->regulatorService->approve();
57+
if ($result === false) {
58+
return false;
6159
}
6260

61+
if (is_countable($result) && count($result) === 0) {
62+
return $result;
63+
}
64+
65+
$this->regulatorService->approve();
66+
6367
return $result;
6468
});
6569
} catch (RecordsNotFoundException|ExceptionInterface $exception) {
66-
$this->regulatorService->purge();
67-
$this->init = false;
68-
6970
throw $exception;
7071
} catch (Throwable $throwable) {
71-
$this->regulatorService->purge();
72-
$this->init = false;
73-
7472
throw new TransactionFailedException(
7573
'Transaction failed. Message: ' . $throwable->getMessage(),
7674
ExceptionInterface::TRANSACTION_FAILED,
7775
$throwable
7876
);
77+
} finally {
78+
$this->regulatorService->purge();
79+
$this->init = false;
7980
}
8081
}
8182
}

src/Internal/Service/StateService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ public function __construct(CacheFactory $cacheFactory)
2525

2626
public function fork(string $uuid, callable $value): void
2727
{
28-
$this->forkCallables->add(self::PREFIX_FORK_CALL . $uuid, $value);
28+
if (! $this->forks->has(self::PREFIX_FORKS . $uuid)) {
29+
$this->forkCallables->put(self::PREFIX_FORK_CALL . $uuid, $value);
30+
}
2931
}
3032

3133
public function get(string $uuid): ?string
3234
{
3335
$callable = $this->forkCallables->pull(self::PREFIX_FORK_CALL . $uuid);
3436
if ($callable !== null) {
35-
$this->forks->put(self::PREFIX_FORKS . $uuid, (string) $callable());
37+
return $this->forks->rememberForever(self::PREFIX_FORKS . $uuid, $callable);
3638
}
3739

3840
return $this->forks->get(self::PREFIX_FORKS . $uuid);
3941
}
4042

4143
public function drop(string $uuid): void
4244
{
43-
$this->forkCallables->delete(self::PREFIX_FORK_CALL . $uuid);
44-
$this->forks->delete(self::PREFIX_FORKS . $uuid);
45+
$this->forkCallables->forget(self::PREFIX_FORK_CALL . $uuid);
46+
$this->forks->forget(self::PREFIX_FORKS . $uuid);
4547
}
4648
}

src/Internal/Service/StorageService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class StorageService implements StorageServiceInterface
1212
{
13-
private const PREFIX = 'wallet_strg::';
13+
private const PREFIX = 'wallet_sg::';
1414

1515
public function __construct(
1616
private MathServiceInterface $mathService,

src/Services/RegulatorService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public function approve(): void
107107
$event = $this->balanceUpdatedEventAssembler->create($wallet);
108108
$this->dispatcherService->dispatch($event);
109109
}
110-
} finally {
111110
$this->dispatcherService->flush();
111+
} finally {
112112
$this->purge();
113113
}
114114
}

0 commit comments

Comments
 (0)