Skip to content

Commit

Permalink
fix safeResetConfirm
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jul 8, 2024
1 parent cf2c845 commit f4d66aa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
12 changes: 1 addition & 11 deletions src/Internal/Observers/TransactionObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Bavix\Wallet\Exceptions\UnconfirmedInvalid;
use Bavix\Wallet\Exceptions\WalletOwnerInvalid;
use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
use Bavix\Wallet\Internal\Exceptions\RecordNotFoundException;
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
Expand All @@ -25,15 +24,6 @@ final class TransactionObserver
*/
public function deleting(Transaction $model): bool
{
return $this->safeResetConfirm($model->wallet, $model);
}

private function safeResetConfirm(Wallet $model, Transaction $transaction): bool
{
try {
return $model->resetConfirm($transaction);
} catch (UnconfirmedInvalid) {
return true;
}
return $model->wallet->safeResetConfirm($model);
}
}
15 changes: 2 additions & 13 deletions src/Internal/Observers/TransferObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Bavix\Wallet\Exceptions\UnconfirmedInvalid;
use Bavix\Wallet\Exceptions\WalletOwnerInvalid;
use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
use Bavix\Wallet\Internal\Exceptions\RecordNotFoundException;
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Services\AtomicServiceInterface;
use Illuminate\Database\RecordsNotFoundException;
Expand All @@ -33,17 +31,8 @@ public function __construct(
public function deleting(Transfer $model): bool
{
return $this->atomicService->blocks([$model->from, $model->to], function () use ($model) {

Check warning on line 33 in src/Internal/Observers/TransferObserver.php

View workflow job for this annotation

GitHub Actions / units (8.3, testing, array, redis)

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ */ public function deleting(Transfer $model): bool { - return $this->atomicService->blocks([$model->from, $model->to], function () use ($model) { + return $this->atomicService->blocks([$model->to], function () use ($model) { return $model->from->safeResetConfirm($model->withdraw) && $model->to->safeResetConfirm($model->deposit); }); } }
return $this->safeResetConfirm($model->from, $model->withdraw)
&& $this->safeResetConfirm($model->to, $model->deposit);
return $model->from->safeResetConfirm($model->withdraw)
&& $model->to->safeResetConfirm($model->deposit);
});
}

private function safeResetConfirm(Wallet $model, Transaction $transaction): bool
{
try {
return $model->resetConfirm($transaction);
} catch (UnconfirmedInvalid) {
return true;
}
}
}
2 changes: 2 additions & 0 deletions src/Traits/CanConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public function safeResetConfirm(Transaction $transaction): bool
{
try {
return $this->resetConfirm($transaction);
} catch (UnconfirmedInvalid) {
return true;
} catch (ExceptionInterface) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Units/Domain/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testSafeUnconfirmed(): void
$transaction = $wallet->deposit(1000, null, false);
self::assertSame(0, $wallet->balanceInt);
self::assertFalse($transaction->confirmed);
self::assertFalse($wallet->safeResetConfirm($transaction));
self::assertTrue($wallet->safeResetConfirm($transaction));
}

public function testWalletOwnerInvalid(): void
Expand Down

0 comments on commit f4d66aa

Please sign in to comment.