From 1a29e92f231ab55a5d5de14547eae7c621af67b9 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 30 Dec 2023 11:32:42 +0300 Subject: [PATCH 01/21] working on a new version --- ...023_12_30_113122_extra_columns_removed.php | 32 +++++++++++++++++++ .../Assembler/TransferDtoAssembler.php | 2 -- src/Internal/Dto/TransferDto.php | 12 ------- src/Internal/Dto/TransferDtoInterface.php | 4 --- .../Transform/TransferDtoTransformer.php | 2 -- src/Models/Transfer.php | 4 --- src/Services/BookkeeperService.php | 6 ---- src/Services/BookkeeperServiceInterface.php | 6 ---- src/Services/RegulatorService.php | 6 ---- src/Services/RegulatorServiceInterface.php | 6 ---- tests/Infra/Models/Item.php | 9 +++--- 11 files changed, 36 insertions(+), 53 deletions(-) create mode 100644 database/2023_12_30_113122_extra_columns_removed.php diff --git a/database/2023_12_30_113122_extra_columns_removed.php b/database/2023_12_30_113122_extra_columns_removed.php new file mode 100644 index 000000000..a049c9307 --- /dev/null +++ b/database/2023_12_30_113122_extra_columns_removed.php @@ -0,0 +1,32 @@ +table(), ['from_type', 'to_type']); + } + + public function down(): void + { + Schema::table($this->table(), static function (Blueprint $table) { + $table->string('from_type') + ->after('from_id') + ; + $table->string('to_type') + ->after('to_id') + ; + }); + } + + private function table(): string + { + return (new Transfer())->getTable(); + } +}; diff --git a/src/Internal/Assembler/TransferDtoAssembler.php b/src/Internal/Assembler/TransferDtoAssembler.php index 18e8590ab..0f2f804fd 100644 --- a/src/Internal/Assembler/TransferDtoAssembler.php +++ b/src/Internal/Assembler/TransferDtoAssembler.php @@ -31,9 +31,7 @@ public function create( $depositId, $withdrawId, $status, - $fromModel->getMorphClass(), $fromModel->getKey(), - $toModel->getMorphClass(), $toModel->getKey(), $discount, $fee diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index 0b972ee25..f50f1b748 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -18,9 +18,7 @@ public function __construct( private readonly int $depositId, private readonly int $withdrawId, private readonly string $status, - private readonly string $fromType, private readonly int|string $fromId, - private readonly string $toType, private readonly int|string $toId, private readonly int $discount, private readonly string $fee @@ -49,21 +47,11 @@ public function getStatus(): string return $this->status; } - public function getFromType(): string - { - return $this->fromType; - } - public function getFromId(): int|string { return $this->fromId; } - public function getToType(): string - { - return $this->toType; - } - public function getToId(): int|string { return $this->toId; diff --git a/src/Internal/Dto/TransferDtoInterface.php b/src/Internal/Dto/TransferDtoInterface.php index 66af853a6..2018de133 100644 --- a/src/Internal/Dto/TransferDtoInterface.php +++ b/src/Internal/Dto/TransferDtoInterface.php @@ -16,12 +16,8 @@ public function getWithdrawId(): int; public function getStatus(): string; - public function getFromType(): string; - public function getFromId(): int|string; - public function getToType(): string; - public function getToId(): int|string; public function getDiscount(): int; diff --git a/src/Internal/Transform/TransferDtoTransformer.php b/src/Internal/Transform/TransferDtoTransformer.php index c9d549816..6aee37dad 100644 --- a/src/Internal/Transform/TransferDtoTransformer.php +++ b/src/Internal/Transform/TransferDtoTransformer.php @@ -15,9 +15,7 @@ public function extract(TransferDtoInterface $dto): array 'deposit_id' => $dto->getDepositId(), 'withdraw_id' => $dto->getWithdrawId(), 'status' => $dto->getStatus(), - 'from_type' => $dto->getFromType(), 'from_id' => $dto->getFromId(), - 'to_type' => $dto->getToType(), 'to_id' => $dto->getToId(), 'discount' => $dto->getDiscount(), 'fee' => $dto->getFee(), diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index 0d43bd422..8b98247d8 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -17,10 +17,8 @@ * @property int $deposit_id * @property int $withdraw_id * @property Wallet $from - * @property class-string $from_type * @property int $from_id * @property Wallet $to - * @property class-string $to_type * @property int $to_id * @property string $uuid * @property string $fee @@ -49,9 +47,7 @@ class Transfer extends Model 'discount', 'deposit_id', 'withdraw_id', - 'from_type', 'from_id', - 'to_type', 'to_id', 'uuid', 'fee', diff --git a/src/Services/BookkeeperService.php b/src/Services/BookkeeperService.php index 2f286beb5..4919330ab 100644 --- a/src/Services/BookkeeperService.php +++ b/src/Services/BookkeeperService.php @@ -21,12 +21,6 @@ public function __construct( ) { } - #[CodeCoverageIgnore] - public function missing(Wallet $wallet): bool - { - return $this->forget($wallet); - } - public function forget(Wallet $wallet): bool { return $this->storageService->forget($wallet->uuid); diff --git a/src/Services/BookkeeperServiceInterface.php b/src/Services/BookkeeperServiceInterface.php index b476a6a12..9c95c185c 100644 --- a/src/Services/BookkeeperServiceInterface.php +++ b/src/Services/BookkeeperServiceInterface.php @@ -12,12 +12,6 @@ */ interface BookkeeperServiceInterface { - /** - * @deprecated Fixed naming. - * @see forget - */ - public function missing(Wallet $wallet): bool; - public function forget(Wallet $wallet): bool; public function amount(Wallet $wallet): string; diff --git a/src/Services/RegulatorService.php b/src/Services/RegulatorService.php index 5bcd5970e..95d16a8ea 100644 --- a/src/Services/RegulatorService.php +++ b/src/Services/RegulatorService.php @@ -40,12 +40,6 @@ public function __construct( ) { } - #[CodeCoverageIgnore] - public function missing(Wallet $wallet): bool - { - return $this->forget($wallet); - } - public function forget(Wallet $wallet): bool { unset($this->wallets[$wallet->uuid]); diff --git a/src/Services/RegulatorServiceInterface.php b/src/Services/RegulatorServiceInterface.php index abb4f8ddc..214942d60 100644 --- a/src/Services/RegulatorServiceInterface.php +++ b/src/Services/RegulatorServiceInterface.php @@ -11,12 +11,6 @@ */ interface RegulatorServiceInterface { - /** - * @deprecated Fixed naming. - * @see forget - */ - public function missing(Wallet $wallet): bool; - public function forget(Wallet $wallet): bool; public function diff(Wallet $wallet): string; diff --git a/tests/Infra/Models/Item.php b/tests/Infra/Models/Item.php index 2ae3e37dd..69d56cbe1 100644 --- a/tests/Infra/Models/Item.php +++ b/tests/Infra/Models/Item.php @@ -14,7 +14,7 @@ use Bavix\Wallet\Traits\HasWallet; use Bavix\Wallet\Traits\HasWallets; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Eloquent\Relations\HasMany; /** * @property string $name @@ -60,15 +60,14 @@ public function getMetaProduct(): ?array /** * @param int[] $walletIds * - * @return MorphMany + * @return HasMany */ - public function boughtGoods(array $walletIds): MorphMany + public function boughtGoods(array $walletIds): HasMany { return app(CastServiceInterface::class) ->getWallet($this) - ->morphMany(Config::classString('wallet.transfer.model', Transfer::class), 'to') + ->hasMany(Config::classString('wallet.transfer.model', Transfer::class), 'to_id') ->where('status', Transfer::STATUS_PAID) - ->where('from_type', Config::classString('wallet.wallet.model', Wallet::class)) ->whereIn('from_id', $walletIds) ; } From 18eb7dcdd5276caaf709c846fadc5635c2a50a1c Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 30 Dec 2023 11:44:57 +0300 Subject: [PATCH 02/21] phpstan fix --- phpstan.src.baseline.neon | 4 ++-- phpstan.tests.baseline.neon | 2 +- src/Internal/Transform/TransferDtoTransformerInterface.php | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/phpstan.src.baseline.neon b/phpstan.src.baseline.neon index d21767c68..73e52eb69 100644 --- a/phpstan.src.baseline.neon +++ b/phpstan.src.baseline.neon @@ -21,12 +21,12 @@ parameters: path: src/Internal/Assembler/TransactionDtoAssembler.php - - message: "#^Parameter \\#6 \\$fromId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" + message: "#^Parameter \\#5 \\$fromId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" count: 1 path: src/Internal/Assembler/TransferDtoAssembler.php - - message: "#^Parameter \\#8 \\$toId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" + message: "#^Parameter \\#6 \\$toId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" count: 1 path: src/Internal/Assembler/TransferDtoAssembler.php diff --git a/phpstan.tests.baseline.neon b/phpstan.tests.baseline.neon index 001f988aa..c84ba2d0b 100644 --- a/phpstan.tests.baseline.neon +++ b/phpstan.tests.baseline.neon @@ -1,7 +1,7 @@ parameters: ignoreErrors: - - message: "#^Method Bavix\\\\Wallet\\\\Test\\\\Infra\\\\Models\\\\Item\\:\\:boughtGoods\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphMany\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphMany\\\\.$#" + message: "#^Method Bavix\\\\Wallet\\\\Test\\\\Infra\\\\Models\\\\Item\\:\\:boughtGoods\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\\\.$#" count: 1 path: tests/Infra/Models/Item.php diff --git a/src/Internal/Transform/TransferDtoTransformerInterface.php b/src/Internal/Transform/TransferDtoTransformerInterface.php index 51bafbc5b..6c72b54d8 100644 --- a/src/Internal/Transform/TransferDtoTransformerInterface.php +++ b/src/Internal/Transform/TransferDtoTransformerInterface.php @@ -15,9 +15,7 @@ interface TransferDtoTransformerInterface * deposit_id: int, * withdraw_id: int, * status: string, - * from_type: string, * from_id: int|string, - * to_type: string, * to_id: int|string, * discount: int, * fee: string, From 83e3de51c9d9f629f478e7979dc5486a96389f41 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 30 Dec 2023 20:34:48 +0300 Subject: [PATCH 03/21] ecs fix --- src/Services/BookkeeperService.php | 1 - src/Services/RegulatorService.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Services/BookkeeperService.php b/src/Services/BookkeeperService.php index 4919330ab..2eb53cf40 100644 --- a/src/Services/BookkeeperService.php +++ b/src/Services/BookkeeperService.php @@ -8,7 +8,6 @@ use Bavix\Wallet\Internal\Service\LockServiceInterface; use Bavix\Wallet\Internal\Service\StorageServiceInterface; use Bavix\Wallet\Models\Wallet; -use PHPUnit\Framework\Attributes\CodeCoverageIgnore; /** * @internal diff --git a/src/Services/RegulatorService.php b/src/Services/RegulatorService.php index 95d16a8ea..98de5dd7d 100644 --- a/src/Services/RegulatorService.php +++ b/src/Services/RegulatorService.php @@ -12,7 +12,6 @@ use Bavix\Wallet\Internal\Service\MathServiceInterface; use Bavix\Wallet\Internal\Service\StorageServiceInterface; use Bavix\Wallet\Models\Wallet; -use PHPUnit\Framework\Attributes\CodeCoverageIgnore; /** * @internal From e7d64c9c6f8283e4d6ec7216a9a7e7de283b7957 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 30 Dec 2023 23:08:23 +0300 Subject: [PATCH 04/21] add native soft delete --- database/2023_12_30_204610_soft_delete.php | 45 ++++++++++ .../Observers/TransactionObserver.php | 29 +++++++ src/Internal/Observers/TransferObserver.php | 38 ++++++++ src/Models/Transaction.php | 15 ++++ src/Models/Transfer.php | 15 ++++ src/Models/Wallet.php | 3 + tests/Units/Domain/BalanceTest.php | 2 +- tests/Units/Domain/SoftDeleteTest.php | 86 +++++++++++++++++++ 8 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 database/2023_12_30_204610_soft_delete.php create mode 100644 src/Internal/Observers/TransactionObserver.php create mode 100644 src/Internal/Observers/TransferObserver.php create mode 100644 tests/Units/Domain/SoftDeleteTest.php diff --git a/database/2023_12_30_204610_soft_delete.php b/database/2023_12_30_204610_soft_delete.php new file mode 100644 index 000000000..552794894 --- /dev/null +++ b/database/2023_12_30_204610_soft_delete.php @@ -0,0 +1,45 @@ +getTable(), static function (Blueprint $table) { + $table->dropUnique(['holder_type', 'holder_id', 'slug']); + + $table->softDeletesTz(); + + $table->unique(['holder_type', 'holder_id', 'slug', 'deleted_at']); + }); + Schema::table((new Transfer())->getTable(), static function (Blueprint $table) { + $table->softDeletesTz(); + }); + Schema::table((new Transaction())->getTable(), static function (Blueprint $table) { + $table->softDeletesTz(); + }); + } + + public function down(): void + { + Schema::table((new Wallet())->getTable(), static function (Blueprint $table) { + $table->dropUnique(['holder_type', 'holder_id', 'slug', 'deleted_at']); + $table->unique(['holder_type', 'holder_id', 'slug']); + + $table->dropSoftDeletes(); + }); + Schema::table((new Transfer())->getTable(), static function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table((new Transaction())->getTable(), static function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + } +}; diff --git a/src/Internal/Observers/TransactionObserver.php b/src/Internal/Observers/TransactionObserver.php new file mode 100644 index 000000000..56ca2bf7b --- /dev/null +++ b/src/Internal/Observers/TransactionObserver.php @@ -0,0 +1,29 @@ +wallet->resetConfirm($model); + } +} diff --git a/src/Internal/Observers/TransferObserver.php b/src/Internal/Observers/TransferObserver.php new file mode 100644 index 000000000..ec1bdee78 --- /dev/null +++ b/src/Internal/Observers/TransferObserver.php @@ -0,0 +1,38 @@ +atomicService->blocks([$model->from, $model->to], function () use ($model) { + return $model->from->resetConfirm($model->withdraw) + && $model->to->resetConfirm($model->deposit); + }); + } +} diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 5672da404..f5b77e99b 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -5,12 +5,15 @@ namespace Bavix\Wallet\Models; use Bavix\Wallet\Interfaces\Wallet; +use Bavix\Wallet\Internal\Observers\TransactionObserver; use Bavix\Wallet\Internal\Service\MathServiceInterface; use Bavix\Wallet\Models\Wallet as WalletModel; use Bavix\Wallet\Services\CastServiceInterface; +use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Database\Eloquent\SoftDeletes; use function config; /** @@ -28,11 +31,16 @@ * @property array $meta * @property Wallet $payable * @property WalletModel $wallet + * @property DateTimeInterface $created_at + * @property DateTimeInterface $updated_at + * @property DateTimeInterface $deleted_at * * @method int getKey() */ class Transaction extends Model { + use SoftDeletes; + final public const TYPE_DEPOSIT = 'deposit'; final public const TYPE_WITHDRAW = 'withdraw'; @@ -113,4 +121,11 @@ public function setAmountFloatAttribute(float|int|string $amount): void $this->amount = $math->round($math->mul($amount, $decimalPlaces)); } + + protected static function boot(): void + { + parent::boot(); + + static::observe(TransactionObserver::class); + } } diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index 8b98247d8..341628837 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -4,8 +4,11 @@ namespace Bavix\Wallet\Models; +use Bavix\Wallet\Internal\Observers\TransferObserver; +use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\SoftDeletes; use function config; /** @@ -24,11 +27,16 @@ * @property string $fee * @property Transaction $deposit * @property Transaction $withdraw + * @property DateTimeInterface $created_at + * @property DateTimeInterface $updated_at + * @property DateTimeInterface $deleted_at * * @method int getKey() */ class Transfer extends Model { + use SoftDeletes; + final public const STATUS_EXCHANGE = 'exchange'; final public const STATUS_TRANSFER = 'transfer'; @@ -103,4 +111,11 @@ public function withdraw(): BelongsTo { return $this->belongsTo(Transaction::class, 'withdraw_id'); } + + protected static function boot(): void + { + parent::boot(); + + static::observe(TransferObserver::class); + } } diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 77c76f739..7cb08667b 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -21,6 +21,7 @@ use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\RecordsNotFoundException; use Illuminate\Support\Str; use function app; @@ -43,6 +44,7 @@ * @property string $currency * @property DateTimeInterface $created_at * @property DateTimeInterface $updated_at + * @property DateTimeInterface $deleted_at * * @method int getKey() */ @@ -52,6 +54,7 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan use CanExchange; use CanPayFloat; use HasGift; + use SoftDeletes; /** * @var string[] diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index 2c8ba7be8..294f92cd4 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -134,7 +134,7 @@ public function testSimple(): void self::assertSame(1000, $wallet->balanceInt); $key = $wallet->getKey(); - self::assertTrue($wallet->delete()); + self::assertTrue($wallet->forceDelete()); self::assertFalse($wallet->exists); self::assertSame($wallet->getKey(), $key); $result = app(RegulatorServiceInterface::class)->increase($wallet, 100); diff --git a/tests/Units/Domain/SoftDeleteTest.php b/tests/Units/Domain/SoftDeleteTest.php new file mode 100644 index 000000000..414a1b406 --- /dev/null +++ b/tests/Units/Domain/SoftDeleteTest.php @@ -0,0 +1,86 @@ +create(); + self::assertFalse($buyer->relationLoaded('wallet')); + self::assertFalse($buyer->wallet->exists); + + $buyer->deposit(1); + + $oldWallet = $buyer->wallet; + + self::assertTrue($buyer->wallet->exists); + self::assertTrue($buyer->wallet->delete()); + self::assertNotNull($buyer->wallet->deleted_at); + + /** @var Buyer $buyer */ + $buyer = Buyer::query()->find($buyer->getKey()); + + $buyer->deposit(2); + + self::assertNotSame($buyer->wallet->getKey(), $oldWallet->getKey()); + + self::assertSame(1, $oldWallet->balanceInt); + self::assertSame(2, $buyer->balanceInt); + } + + public function testTransactionDelete(): void + { + /** @var Buyer $buyer */ + $buyer = BuyerFactory::new()->create(); + self::assertFalse($buyer->relationLoaded('wallet')); + self::assertFalse($buyer->wallet->exists); + + $transaction = $buyer->deposit(1); + + self::assertTrue($buyer->wallet->exists); + self::assertSame(1, $buyer->balanceInt); + + self::assertTrue($transaction->delete()); + + self::assertSame(0, $buyer->balanceInt); + self::assertFalse($transaction->confirmed); + } + + public function testTransferDelete(): void + { + /** @var Buyer $user1 */ + /** @var Buyer $user2 */ + [$user1, $user2] = BuyerFactory::times(2)->create(); + + self::assertFalse($user1->relationLoaded('wallet')); + self::assertFalse($user1->wallet->exists); + + self::assertFalse($user2->relationLoaded('wallet')); + self::assertFalse($user2->wallet->exists); + + $transfer = $user1->forceTransfer($user2, 100); + + self::assertNotNull($transfer); + self::assertSame(100, $transfer->deposit->amount); + self::assertSame(-100, $transfer->withdraw->amount); + + self::assertSame(-100, $user1->balanceInt); + self::assertSame(100, $user2->balanceInt); + + self::assertTrue($transfer->delete()); + + self::assertSame(0, $user1->balanceInt); + self::assertSame(0, $user2->balanceInt); + } +} From 93437add4c8333b47bc43c88209fc0b9626182bd Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 30 Dec 2023 23:31:18 +0300 Subject: [PATCH 05/21] fix default wallet --- database/2023_12_30_204610_soft_delete.php | 7 ----- src/Traits/MorphOneWallet.php | 1 + tests/Units/Domain/SoftDeleteTest.php | 30 ++++++++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/database/2023_12_30_204610_soft_delete.php b/database/2023_12_30_204610_soft_delete.php index 552794894..3b84c9e58 100644 --- a/database/2023_12_30_204610_soft_delete.php +++ b/database/2023_12_30_204610_soft_delete.php @@ -13,11 +13,7 @@ public function up(): void { Schema::table((new Wallet())->getTable(), static function (Blueprint $table) { - $table->dropUnique(['holder_type', 'holder_id', 'slug']); - $table->softDeletesTz(); - - $table->unique(['holder_type', 'holder_id', 'slug', 'deleted_at']); }); Schema::table((new Transfer())->getTable(), static function (Blueprint $table) { $table->softDeletesTz(); @@ -30,9 +26,6 @@ public function up(): void public function down(): void { Schema::table((new Wallet())->getTable(), static function (Blueprint $table) { - $table->dropUnique(['holder_type', 'holder_id', 'slug', 'deleted_at']); - $table->unique(['holder_type', 'holder_id', 'slug']); - $table->dropSoftDeletes(); }); Schema::table((new Transfer())->getTable(), static function (Blueprint $table) { diff --git a/src/Traits/MorphOneWallet.php b/src/Traits/MorphOneWallet.php index f78184b1c..1b27dbd60 100644 --- a/src/Traits/MorphOneWallet.php +++ b/src/Traits/MorphOneWallet.php @@ -31,6 +31,7 @@ public function wallet(): MorphOne return $castService ->getHolder($this) ->morphOne($related, 'holder') + ->withTrashed() ->where('slug', config('wallet.wallet.default.slug', 'default')) ->withDefault(static function (WalletModel $wallet, object $holder) use ($castService) { $model = $castService->getModel($holder); diff --git a/tests/Units/Domain/SoftDeleteTest.php b/tests/Units/Domain/SoftDeleteTest.php index 414a1b406..816c552bb 100644 --- a/tests/Units/Domain/SoftDeleteTest.php +++ b/tests/Units/Domain/SoftDeleteTest.php @@ -33,6 +33,32 @@ public function testDefaultWalletSoftDelete(): void $buyer->deposit(2); + self::assertSame($buyer->wallet->getKey(), $oldWallet->getKey()); + + self::assertSame(3, $oldWallet->balanceInt); + self::assertSame(3, $buyer->balanceInt); + } + + public function testDefaultWalletForceDelete(): void + { + /** @var Buyer $buyer */ + $buyer = BuyerFactory::new()->create(); + self::assertFalse($buyer->relationLoaded('wallet')); + self::assertFalse($buyer->wallet->exists); + + $buyer->deposit(1); + + $oldWallet = $buyer->wallet; + + self::assertTrue($buyer->wallet->exists); + self::assertTrue($buyer->wallet->forceDelete()); + self::assertFalse($buyer->wallet->exists); + + /** @var Buyer $buyer */ + $buyer = Buyer::query()->find($buyer->getKey()); + + $buyer->deposit(2); + self::assertNotSame($buyer->wallet->getKey(), $oldWallet->getKey()); self::assertSame(1, $oldWallet->balanceInt); @@ -72,8 +98,8 @@ public function testTransferDelete(): void $transfer = $user1->forceTransfer($user2, 100); self::assertNotNull($transfer); - self::assertSame(100, $transfer->deposit->amount); - self::assertSame(-100, $transfer->withdraw->amount); + self::assertSame(100, $transfer->deposit->amountInt); + self::assertSame(-100, $transfer->withdraw->amountInt); self::assertSame(-100, $user1->balanceInt); self::assertSame(100, $user2->balanceInt); From 6f06d2f74a278569fd28abc445f1163ca34930ab Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 00:06:52 +0300 Subject: [PATCH 06/21] update baseline --- phpstan.src.baseline.neon | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpstan.src.baseline.neon b/phpstan.src.baseline.neon index 73e52eb69..36daaf66c 100644 --- a/phpstan.src.baseline.neon +++ b/phpstan.src.baseline.neon @@ -61,18 +61,18 @@ parameters: path: src/Models/Transfer.php - - message: "#^Cannot cast mixed to string\\.$#" - count: 1 + message: "#^Call to an undefined method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphOne\\:\\:withTrashed\\(\\)\\.$#" + count: 2 path: src/Models/Wallet.php - - message: "#^Method Bavix\\\\Wallet\\\\Models\\\\Wallet\\:\\:getAvailableBalanceAttribute\\(\\) should return float\\|int\\|string but returns mixed\\.$#" + message: "#^Cannot cast mixed to string\\.$#" count: 1 path: src/Models/Wallet.php - - message: "#^Method Bavix\\\\Wallet\\\\Models\\\\Wallet\\:\\:wallet\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphOne\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphOne\\\\.$#" - count: 2 + message: "#^Method Bavix\\\\Wallet\\\\Models\\\\Wallet\\:\\:getAvailableBalanceAttribute\\(\\) should return float\\|int\\|string but returns mixed\\.$#" + count: 1 path: src/Models/Wallet.php - From ce948f2f4ac006a5b1308f5e5b983dabe06bb763 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 00:08:46 +0300 Subject: [PATCH 07/21] add namespace --- database/2018_11_06_222923_create_transactions_table.php | 2 ++ database/2018_11_07_192923_create_transfers_table.php | 2 ++ database/2018_11_15_124230_create_wallets_table.php | 2 ++ database/2021_11_02_202021_update_wallets_uuid_table.php | 2 ++ database/2023_12_30_113122_extra_columns_removed.php | 2 ++ database/2023_12_30_204610_soft_delete.php | 2 ++ 6 files changed, 12 insertions(+) diff --git a/database/2018_11_06_222923_create_transactions_table.php b/database/2018_11_06_222923_create_transactions_table.php index 87e891365..5a5af5df8 100644 --- a/database/2018_11_06_222923_create_transactions_table.php +++ b/database/2018_11_06_222923_create_transactions_table.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Models\Transaction; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/database/2018_11_07_192923_create_transfers_table.php b/database/2018_11_07_192923_create_transfers_table.php index f003d941c..27228e6d1 100644 --- a/database/2018_11_07_192923_create_transfers_table.php +++ b/database/2018_11_07_192923_create_transfers_table.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Illuminate\Database\Migrations\Migration; diff --git a/database/2018_11_15_124230_create_wallets_table.php b/database/2018_11_15_124230_create_wallets_table.php index 432d2e595..8e7bb6a7a 100644 --- a/database/2018_11_15_124230_create_wallets_table.php +++ b/database/2018_11_15_124230_create_wallets_table.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Migrations\Migration; diff --git a/database/2021_11_02_202021_update_wallets_uuid_table.php b/database/2021_11_02_202021_update_wallets_uuid_table.php index 3125848c5..84a3b76bf 100644 --- a/database/2021_11_02_202021_update_wallets_uuid_table.php +++ b/database/2021_11_02_202021_update_wallets_uuid_table.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Migrations\Migration; diff --git a/database/2023_12_30_113122_extra_columns_removed.php b/database/2023_12_30_113122_extra_columns_removed.php index a049c9307..b2b915f5e 100644 --- a/database/2023_12_30_113122_extra_columns_removed.php +++ b/database/2023_12_30_113122_extra_columns_removed.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Models\Transfer; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/database/2023_12_30_204610_soft_delete.php b/database/2023_12_30_204610_soft_delete.php index 3b84c9e58..189d2946f 100644 --- a/database/2023_12_30_204610_soft_delete.php +++ b/database/2023_12_30_204610_soft_delete.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace database; + use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Bavix\Wallet\Models\Wallet; From b2d1fc585f8784e4266b8509bf049c8a9a70f4b8 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 00:15:05 +0300 Subject: [PATCH 08/21] minimum php version changed --- .github/workflows/code-style.yaml | 2 +- .github/workflows/deptrac.yaml | 2 +- .github/workflows/phpstan.yaml | 2 +- .github/workflows/phpunits.yaml | 2 +- .github/workflows/rector.yaml | 2 +- composer.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml index 87838aefc..cc0b1dd45 100644 --- a/.github/workflows/code-style.yaml +++ b/.github/workflows/code-style.yaml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/deptrac.yaml b/.github/workflows/deptrac.yaml index 81f63762d..7ba02bba3 100644 --- a/.github/workflows/deptrac.yaml +++ b/.github/workflows/deptrac.yaml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index 984268632..fdf50e299 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/phpunits.yaml b/.github/workflows/phpunits.yaml index 7de2ac3c5..0fc8630d8 100644 --- a/.github/workflows/phpunits.yaml +++ b/.github/workflows/phpunits.yaml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - php-versions: [8.1, 8.2, 8.3] + php-versions: [8.2, 8.3] databases: [testing, pgsql, mysql, mariadb] caches: [array, redis, memcached, database] locks: [redis, memcached] diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index 91625ff10..d34ee97e7 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 extensions: bcmath env: runner: self-hosted diff --git a/composer.json b/composer.json index c8ee58c60..b87456854 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-json": "*", "ext-pdo": "*", "brick/math": "~0.10", From 486b26e28e9c96bb9b67944ee18314825135829d Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 07:49:20 +0300 Subject: [PATCH 09/21] revert namespace --- database/2018_11_06_222923_create_transactions_table.php | 2 -- database/2018_11_07_192923_create_transfers_table.php | 2 -- database/2018_11_15_124230_create_wallets_table.php | 2 -- database/2021_11_02_202021_update_wallets_uuid_table.php | 2 -- database/2023_12_30_113122_extra_columns_removed.php | 2 -- database/2023_12_30_204610_soft_delete.php | 2 -- 6 files changed, 12 deletions(-) diff --git a/database/2018_11_06_222923_create_transactions_table.php b/database/2018_11_06_222923_create_transactions_table.php index 5a5af5df8..87e891365 100644 --- a/database/2018_11_06_222923_create_transactions_table.php +++ b/database/2018_11_06_222923_create_transactions_table.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Models\Transaction; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/database/2018_11_07_192923_create_transfers_table.php b/database/2018_11_07_192923_create_transfers_table.php index 27228e6d1..f003d941c 100644 --- a/database/2018_11_07_192923_create_transfers_table.php +++ b/database/2018_11_07_192923_create_transfers_table.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Illuminate\Database\Migrations\Migration; diff --git a/database/2018_11_15_124230_create_wallets_table.php b/database/2018_11_15_124230_create_wallets_table.php index 8e7bb6a7a..432d2e595 100644 --- a/database/2018_11_15_124230_create_wallets_table.php +++ b/database/2018_11_15_124230_create_wallets_table.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Migrations\Migration; diff --git a/database/2021_11_02_202021_update_wallets_uuid_table.php b/database/2021_11_02_202021_update_wallets_uuid_table.php index 84a3b76bf..3125848c5 100644 --- a/database/2021_11_02_202021_update_wallets_uuid_table.php +++ b/database/2021_11_02_202021_update_wallets_uuid_table.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Migrations\Migration; diff --git a/database/2023_12_30_113122_extra_columns_removed.php b/database/2023_12_30_113122_extra_columns_removed.php index b2b915f5e..a049c9307 100644 --- a/database/2023_12_30_113122_extra_columns_removed.php +++ b/database/2023_12_30_113122_extra_columns_removed.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Models\Transfer; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/database/2023_12_30_204610_soft_delete.php b/database/2023_12_30_204610_soft_delete.php index 189d2946f..3b84c9e58 100644 --- a/database/2023_12_30_204610_soft_delete.php +++ b/database/2023_12_30_204610_soft_delete.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace database; - use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Bavix\Wallet\Models\Wallet; From 3b2d146043798eb4c8afd5ce0a0c9e2f0190a548 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 08:00:03 +0300 Subject: [PATCH 10/21] add units --- ...SoftDeleteTest.php => SoftDeletesTest.php} | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) rename tests/Units/Domain/{SoftDeleteTest.php => SoftDeletesTest.php} (60%) diff --git a/tests/Units/Domain/SoftDeleteTest.php b/tests/Units/Domain/SoftDeletesTest.php similarity index 60% rename from tests/Units/Domain/SoftDeleteTest.php rename to tests/Units/Domain/SoftDeletesTest.php index 816c552bb..cfbc7ed74 100644 --- a/tests/Units/Domain/SoftDeleteTest.php +++ b/tests/Units/Domain/SoftDeletesTest.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Test\Units\Domain; +use Bavix\Wallet\Exceptions\UnconfirmedInvalid; use Bavix\Wallet\Test\Infra\Factories\BuyerFactory; use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\TestCase; @@ -11,7 +12,7 @@ /** * @internal */ -final class SoftDeleteTest extends TestCase +final class SoftDeletesTest extends TestCase { public function testDefaultWalletSoftDelete(): void { @@ -81,6 +82,28 @@ public function testTransactionDelete(): void self::assertSame(0, $buyer->balanceInt); self::assertFalse($transaction->confirmed); + self::assertNotNull($transaction->deleted_at); + } + + public function testTransactionDeleteIfNotConfirmed(): void + { + $this->expectException(UnconfirmedInvalid::class); + + /** @var Buyer $buyer */ + $buyer = BuyerFactory::new()->create(); + self::assertFalse($buyer->relationLoaded('wallet')); + self::assertFalse($buyer->wallet->exists); + + $transaction = $buyer->deposit(1); + + self::assertTrue($buyer->wallet->exists); + self::assertSame(1, $buyer->balanceInt); + + self::assertTrue($buyer->wallet->resetConfirm($transaction)); + + self::assertSame(0, $buyer->balanceInt); + + self::assertTrue($transaction->delete()); } public function testTransferDelete(): void @@ -104,9 +127,46 @@ public function testTransferDelete(): void self::assertSame(-100, $user1->balanceInt); self::assertSame(100, $user2->balanceInt); + self::assertTrue($transfer->deposit->confirmed); + self::assertTrue($transfer->withdraw->confirmed); + self::assertTrue($transfer->delete()); self::assertSame(0, $user1->balanceInt); self::assertSame(0, $user2->balanceInt); + + self::assertFalse($transfer->deposit->confirmed); + self::assertFalse($transfer->withdraw->confirmed); + } + + public function testTransferDeleteIfNotConfirmed(): void + { + $this->expectException(UnconfirmedInvalid::class); + + /** @var Buyer $user1 */ + /** @var Buyer $user2 */ + [$user1, $user2] = BuyerFactory::times(2)->create(); + + self::assertFalse($user1->relationLoaded('wallet')); + self::assertFalse($user1->wallet->exists); + + self::assertFalse($user2->relationLoaded('wallet')); + self::assertFalse($user2->wallet->exists); + + $transfer = $user1->forceTransfer($user2, 100); + + self::assertNotNull($transfer); + self::assertSame(100, $transfer->deposit->amountInt); + self::assertSame(-100, $transfer->withdraw->amountInt); + + self::assertSame(-100, $user1->balanceInt); + self::assertSame(100, $user2->balanceInt); + + self::assertTrue($transfer->deposit->confirmed); + self::assertTrue($transfer->withdraw->confirmed); + + self::assertTrue($user1->wallet->resetConfirm($transfer->withdraw)); + + self::assertTrue($transfer->delete()); } } From 15e7ee101812ecdaf7673c8b541d12f83ba13260 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 08:27:42 +0300 Subject: [PATCH 11/21] update composer.json --- composer.json | 16 +++++----- phpstan.common.neon | 54 +--------------------------------- phpstan.src.neon | 44 ++++++++++++++++------------ phpstan.tests.neon | 55 ++++++++++++++++++++--------------- src/Traits/MorphOneWallet.php | 4 +-- 5 files changed, 69 insertions(+), 104 deletions(-) diff --git a/composer.json b/composer.json index b87456854..7aa9b6cde 100644 --- a/composer.json +++ b/composer.json @@ -32,17 +32,17 @@ "ramsey/uuid": "^4.0" }, "require-dev": { - "brianium/paratest": "^7.2", - "cknow/laravel-money": "^7.1", - "ergebnis/phpstan-rules": "^1.0", + "brianium/paratest": "^7.3", + "cknow/laravel-money": "^7.2", + "ergebnis/phpstan-rules": "^2.1", "infection/infection": "~0.27", "laravel/cashier": "^15.0", - "nunomaduro/collision": "^7.7", - "nunomaduro/larastan": "^2.6", - "orchestra/testbench": "^8.5", + "nunomaduro/collision": "^7.10", + "nunomaduro/larastan": "^2.7", + "orchestra/testbench": "^8.19", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.2", - "rector/rector": "^0.17", + "phpunit/phpunit": "^10.5", + "rector/rector": "^0.18", "symplify/easy-coding-standard": "^12.0" }, "suggest": { diff --git a/phpstan.common.neon b/phpstan.common.neon index 8d97ee03a..927803fd1 100644 --- a/phpstan.common.neon +++ b/phpstan.common.neon @@ -1,60 +1,8 @@ includes: - vendor/nunomaduro/larastan/extension.neon + - vendor/ergebnis/phpstan-rules/rules.neon parameters: level: 9 fileExtensions: - php - -parametersSchema: - ergebnis: structure([ - allowAbstractClasses: bool() - classesAllowedToBeExtended: listOf(string()) - classesNotRequiredToBeAbstractOrFinal: listOf(string()) - interfacesImplementedByContainers: listOf(string()) - ]) - -rules: - - Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Expressions\NoCompactRule - - Ergebnis\PHPStan\Rules\Expressions\NoEmptyRule - - Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule - - Ergebnis\PHPStan\Rules\Expressions\NoEvalRule - - Ergebnis\PHPStan\Rules\Expressions\NoIssetRule - - Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule - - Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule - - Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule - - Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule - - Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule - - Ergebnis\PHPStan\Rules\Statements\NoSwitchRule - -services: - - - class: Ergebnis\PHPStan\Rules\Classes\FinalRule - arguments: - allowAbstractClasses: %ergebnis.allowAbstractClasses% - classesNotRequiredToBeAbstractOrFinal: %ergebnis.classesNotRequiredToBeAbstractOrFinal% - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Classes\NoExtendsRule - arguments: - classesAllowedToBeExtended: %ergebnis.classesAllowedToBeExtended% - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule - arguments: - interfacesImplementedByContainers: %ergebnis.interfacesImplementedByContainers% - tags: - - phpstan.rules.rule diff --git a/phpstan.src.neon b/phpstan.src.neon index 7952daa9c..d552a5775 100644 --- a/phpstan.src.neon +++ b/phpstan.src.neon @@ -7,24 +7,32 @@ parameters: fileExtensions: - php ergebnis: - allowAbstractClasses: true - classesAllowedToBeExtended: - # laravel - - Illuminate\Support\ServiceProvider - - Illuminate\Database\Eloquent\Model + noParameterWithNullableTypeDeclaration: + enabled: false + noNullableReturnTypeDeclaration: + enabled: false + noParameterWithNullDefaultValue: + enabled: false + final: + allowAbstractClasses: true + classesNotRequiredToBeAbstractOrFinal: + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction + noExtends: + classesAllowedToBeExtended: + # laravel + - Illuminate\Support\ServiceProvider + - Illuminate\Database\Eloquent\Model - # php exceptions - - LogicException - - RuntimeException - - UnderflowException - - UnexpectedValueException - - InvalidArgumentException - - classesNotRequiredToBeAbstractOrFinal: - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction - interfacesImplementedByContainers: - - Psr\Container\ContainerInterface + # php exceptions + - LogicException + - RuntimeException + - UnderflowException + - UnexpectedValueException + - InvalidArgumentException + noParameterWithContainerTypeDeclaration: + interfacesImplementedByContainers: + - Psr\Container\ContainerInterface paths: - src/ diff --git a/phpstan.tests.neon b/phpstan.tests.neon index 85854cf85..a39aa43d5 100644 --- a/phpstan.tests.neon +++ b/phpstan.tests.neon @@ -9,32 +9,41 @@ parameters: fileExtensions: - php ergebnis: - allowAbstractClasses: false - classesAllowedToBeExtended: - # laravel - - Illuminate\Support\ServiceProvider - - Illuminate\Database\Eloquent\Model - - Illuminate\Database\Migrations\Migration - - Illuminate\Database\Eloquent\Factories\Factory + noParameterWithNullableTypeDeclaration: + enabled: false + noNullableReturnTypeDeclaration: + enabled: false + noParameterWithNullDefaultValue: + enabled: false + final: + allowAbstractClasses: false + classesNotRequiredToBeAbstractOrFinal: + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction + noExtends: + classesAllowedToBeExtended: + # laravel + - Illuminate\Support\ServiceProvider + - Illuminate\Database\Eloquent\Model + - Illuminate\Database\Migrations\Migration + - Illuminate\Database\Eloquent\Factories\Factory - # php exceptions - - RuntimeException - - InvalidArgumentException + # php exceptions + - RuntimeException + - InvalidArgumentException - # phpunit - - Orchestra\Testbench\TestCase - - Bavix\Wallet\Test\Infra\TestCase + # phpunit + - Orchestra\Testbench\TestCase + - Bavix\Wallet\Test\Infra\TestCase - # wallet - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction + # wallet + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction - classesNotRequiredToBeAbstractOrFinal: - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction - interfacesImplementedByContainers: - - Psr\Container\ContainerInterface + noParameterWithContainerTypeDeclaration: + interfacesImplementedByContainers: + - Psr\Container\ContainerInterface paths: - tests/ diff --git a/src/Traits/MorphOneWallet.php b/src/Traits/MorphOneWallet.php index 1b27dbd60..196ba658d 100644 --- a/src/Traits/MorphOneWallet.php +++ b/src/Traits/MorphOneWallet.php @@ -56,10 +56,10 @@ public function wallet(): MorphOne public function getWalletAttribute(): ?WalletModel { - /** @var WalletModel $wallet */ + /** @var WalletModel|null $wallet */ $wallet = $this->getRelationValue('wallet'); - if (! $wallet->relationLoaded('holder')) { + if ($wallet && ! $wallet->relationLoaded('holder')) { $holder = app(CastServiceInterface::class)->getHolder($this); $wallet->setRelation('holder', $holder->withoutRelations()); } From 873bbc225e524073f0d0a115063d3512e37949f0 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 31 Dec 2023 08:27:42 +0300 Subject: [PATCH 12/21] add FormatterServiceInterface --- composer.json | 16 +++++----- config/config.php | 2 ++ phpstan.common.neon | 54 +--------------------------------- phpstan.src.neon | 44 ++++++++++++++++------------ phpstan.tests.neon | 55 ++++++++++++++++++++--------------- src/Traits/HasWalletFloat.php | 9 +++--- src/Traits/MorphOneWallet.php | 4 +-- src/WalletServiceProvider.php | 4 +++ 8 files changed, 80 insertions(+), 108 deletions(-) diff --git a/composer.json b/composer.json index b87456854..7aa9b6cde 100644 --- a/composer.json +++ b/composer.json @@ -32,17 +32,17 @@ "ramsey/uuid": "^4.0" }, "require-dev": { - "brianium/paratest": "^7.2", - "cknow/laravel-money": "^7.1", - "ergebnis/phpstan-rules": "^1.0", + "brianium/paratest": "^7.3", + "cknow/laravel-money": "^7.2", + "ergebnis/phpstan-rules": "^2.1", "infection/infection": "~0.27", "laravel/cashier": "^15.0", - "nunomaduro/collision": "^7.7", - "nunomaduro/larastan": "^2.6", - "orchestra/testbench": "^8.5", + "nunomaduro/collision": "^7.10", + "nunomaduro/larastan": "^2.7", + "orchestra/testbench": "^8.19", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.2", - "rector/rector": "^0.17", + "phpunit/phpunit": "^10.5", + "rector/rector": "^0.18", "symplify/easy-coding-standard": "^12.0" }, "suggest": { diff --git a/config/config.php b/config/config.php index 5bdcf0ac3..937109a22 100644 --- a/config/config.php +++ b/config/config.php @@ -44,6 +44,7 @@ use Bavix\Wallet\Services\DiscountService; use Bavix\Wallet\Services\EagerLoaderService; use Bavix\Wallet\Services\ExchangeService; +use Bavix\Wallet\Services\FormatterService; use Bavix\Wallet\Services\PrepareService; use Bavix\Wallet\Services\PurchaseService; use Bavix\Wallet\Services\RegulatorService; @@ -110,6 +111,7 @@ 'discount' => DiscountService::class, 'eager_loader' => EagerLoaderService::class, 'exchange' => ExchangeService::class, + 'formatter' => FormatterService::class, 'prepare' => PrepareService::class, 'purchase' => PurchaseService::class, 'tax' => TaxService::class, diff --git a/phpstan.common.neon b/phpstan.common.neon index 8d97ee03a..927803fd1 100644 --- a/phpstan.common.neon +++ b/phpstan.common.neon @@ -1,60 +1,8 @@ includes: - vendor/nunomaduro/larastan/extension.neon + - vendor/ergebnis/phpstan-rules/rules.neon parameters: level: 9 fileExtensions: - php - -parametersSchema: - ergebnis: structure([ - allowAbstractClasses: bool() - classesAllowedToBeExtended: listOf(string()) - classesNotRequiredToBeAbstractOrFinal: listOf(string()) - interfacesImplementedByContainers: listOf(string()) - ]) - -rules: - - Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Expressions\NoCompactRule - - Ergebnis\PHPStan\Rules\Expressions\NoEmptyRule - - Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule - - Ergebnis\PHPStan\Rules\Expressions\NoEvalRule - - Ergebnis\PHPStan\Rules\Expressions\NoIssetRule - - Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule - - Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule - - Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule - - Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule - - Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule - - Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule - - Ergebnis\PHPStan\Rules\Statements\NoSwitchRule - -services: - - - class: Ergebnis\PHPStan\Rules\Classes\FinalRule - arguments: - allowAbstractClasses: %ergebnis.allowAbstractClasses% - classesNotRequiredToBeAbstractOrFinal: %ergebnis.classesNotRequiredToBeAbstractOrFinal% - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Classes\NoExtendsRule - arguments: - classesAllowedToBeExtended: %ergebnis.classesAllowedToBeExtended% - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule - tags: - - phpstan.rules.rule - - - - class: Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule - arguments: - interfacesImplementedByContainers: %ergebnis.interfacesImplementedByContainers% - tags: - - phpstan.rules.rule diff --git a/phpstan.src.neon b/phpstan.src.neon index 7952daa9c..d552a5775 100644 --- a/phpstan.src.neon +++ b/phpstan.src.neon @@ -7,24 +7,32 @@ parameters: fileExtensions: - php ergebnis: - allowAbstractClasses: true - classesAllowedToBeExtended: - # laravel - - Illuminate\Support\ServiceProvider - - Illuminate\Database\Eloquent\Model + noParameterWithNullableTypeDeclaration: + enabled: false + noNullableReturnTypeDeclaration: + enabled: false + noParameterWithNullDefaultValue: + enabled: false + final: + allowAbstractClasses: true + classesNotRequiredToBeAbstractOrFinal: + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction + noExtends: + classesAllowedToBeExtended: + # laravel + - Illuminate\Support\ServiceProvider + - Illuminate\Database\Eloquent\Model - # php exceptions - - LogicException - - RuntimeException - - UnderflowException - - UnexpectedValueException - - InvalidArgumentException - - classesNotRequiredToBeAbstractOrFinal: - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction - interfacesImplementedByContainers: - - Psr\Container\ContainerInterface + # php exceptions + - LogicException + - RuntimeException + - UnderflowException + - UnexpectedValueException + - InvalidArgumentException + noParameterWithContainerTypeDeclaration: + interfacesImplementedByContainers: + - Psr\Container\ContainerInterface paths: - src/ diff --git a/phpstan.tests.neon b/phpstan.tests.neon index 85854cf85..a39aa43d5 100644 --- a/phpstan.tests.neon +++ b/phpstan.tests.neon @@ -9,32 +9,41 @@ parameters: fileExtensions: - php ergebnis: - allowAbstractClasses: false - classesAllowedToBeExtended: - # laravel - - Illuminate\Support\ServiceProvider - - Illuminate\Database\Eloquent\Model - - Illuminate\Database\Migrations\Migration - - Illuminate\Database\Eloquent\Factories\Factory + noParameterWithNullableTypeDeclaration: + enabled: false + noNullableReturnTypeDeclaration: + enabled: false + noParameterWithNullDefaultValue: + enabled: false + final: + allowAbstractClasses: false + classesNotRequiredToBeAbstractOrFinal: + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction + noExtends: + classesAllowedToBeExtended: + # laravel + - Illuminate\Support\ServiceProvider + - Illuminate\Database\Eloquent\Model + - Illuminate\Database\Migrations\Migration + - Illuminate\Database\Eloquent\Factories\Factory - # php exceptions - - RuntimeException - - InvalidArgumentException + # php exceptions + - RuntimeException + - InvalidArgumentException - # phpunit - - Orchestra\Testbench\TestCase - - Bavix\Wallet\Test\Infra\TestCase + # phpunit + - Orchestra\Testbench\TestCase + - Bavix\Wallet\Test\Infra\TestCase - # wallet - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction + # wallet + - Bavix\Wallet\Models\Wallet + - Bavix\Wallet\Models\Transfer + - Bavix\Wallet\Models\Transaction - classesNotRequiredToBeAbstractOrFinal: - - Bavix\Wallet\Models\Wallet - - Bavix\Wallet\Models\Transfer - - Bavix\Wallet\Models\Transaction - interfacesImplementedByContainers: - - Psr\Container\ContainerInterface + noParameterWithContainerTypeDeclaration: + interfacesImplementedByContainers: + - Psr\Container\ContainerInterface paths: - tests/ diff --git a/src/Traits/HasWalletFloat.php b/src/Traits/HasWalletFloat.php index 873691c5e..7dc1d5784 100644 --- a/src/Traits/HasWalletFloat.php +++ b/src/Traits/HasWalletFloat.php @@ -15,6 +15,7 @@ use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Bavix\Wallet\Services\CastServiceInterface; +use Bavix\Wallet\Services\FormatterServiceInterface; use Illuminate\Database\RecordsNotFoundException; /** @@ -147,12 +148,12 @@ public function forceTransferFloat( public function getBalanceFloatAttribute(): string { - $math = app(MathServiceInterface::class); $wallet = app(CastServiceInterface::class)->getWallet($this); - $decimalPlacesValue = $wallet->decimal_places; - $decimalPlaces = $math->powTen($decimalPlacesValue); - return $math->div($wallet->getBalanceAttribute(), $decimalPlaces, $decimalPlacesValue); + return app(FormatterServiceInterface::class)->floatValue( + $wallet->getBalanceAttribute(), + $wallet->decimal_places, + ); } public function getBalanceFloatNumAttribute(): float diff --git a/src/Traits/MorphOneWallet.php b/src/Traits/MorphOneWallet.php index 1b27dbd60..196ba658d 100644 --- a/src/Traits/MorphOneWallet.php +++ b/src/Traits/MorphOneWallet.php @@ -56,10 +56,10 @@ public function wallet(): MorphOne public function getWalletAttribute(): ?WalletModel { - /** @var WalletModel $wallet */ + /** @var WalletModel|null $wallet */ $wallet = $this->getRelationValue('wallet'); - if (! $wallet->relationLoaded('holder')) { + if ($wallet && ! $wallet->relationLoaded('holder')) { $holder = app(CastServiceInterface::class)->getHolder($this); $wallet->setRelation('holder', $holder->withoutRelations()); } diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index a7ae10136..bb121d86b 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -92,6 +92,8 @@ use Bavix\Wallet\Services\EagerLoaderServiceInterface; use Bavix\Wallet\Services\ExchangeService; use Bavix\Wallet\Services\ExchangeServiceInterface; +use Bavix\Wallet\Services\FormatterService; +use Bavix\Wallet\Services\FormatterServiceInterface; use Bavix\Wallet\Services\PrepareService; use Bavix\Wallet\Services\PrepareServiceInterface; use Bavix\Wallet\Services\PurchaseService; @@ -274,6 +276,7 @@ private function services(array $configure, array $cache): void $configure['eager_loader'] ?? EagerLoaderService::class ); $this->app->singleton(ExchangeServiceInterface::class, $configure['exchange'] ?? ExchangeService::class); + $this->app->singleton(FormatterServiceInterface::class, $configure['formatter'] ?? FormatterService::class); $this->app->singleton(PrepareServiceInterface::class, $configure['prepare'] ?? PrepareService::class); $this->app->singleton(PurchaseServiceInterface::class, $configure['purchase'] ?? PurchaseService::class); $this->app->singleton(TaxServiceInterface::class, $configure['tax'] ?? TaxService::class); @@ -466,6 +469,7 @@ private function servicesProviders(): array DiscountServiceInterface::class, EagerLoaderServiceInterface::class, ExchangeServiceInterface::class, + FormatterServiceInterface::class, PrepareServiceInterface::class, PurchaseServiceInterface::class, TaxServiceInterface::class, From 9d2fdc205d1a6d2326532cc7c10953e6dc5e2c9a Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 10:25:41 +0300 Subject: [PATCH 13/21] add FormatterServiceInterface --- src/Services/FormatterService.php | 24 ++++++++++ src/Services/FormatterServiceInterface.php | 15 ++++++ tests/Units/Service/FormatterTest.php | 55 ++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/Services/FormatterService.php create mode 100644 src/Services/FormatterServiceInterface.php create mode 100644 tests/Units/Service/FormatterTest.php diff --git a/src/Services/FormatterService.php b/src/Services/FormatterService.php new file mode 100644 index 000000000..b078cfd14 --- /dev/null +++ b/src/Services/FormatterService.php @@ -0,0 +1,24 @@ +power($decimalPlaces) + ->multipliedBy(BigDecimal::of($amount)) + ->toScale(0, RoundingMode::DOWN); + } + + public function floatValue(string|int|float $amount, int $decimalPlaces): string + { + return (string) BigDecimal::ofUnscaledValue($amount, $decimalPlaces); + } +} diff --git a/src/Services/FormatterServiceInterface.php b/src/Services/FormatterServiceInterface.php new file mode 100644 index 000000000..e2d8eee2f --- /dev/null +++ b/src/Services/FormatterServiceInterface.php @@ -0,0 +1,15 @@ +floatValue('12345', 3); + + self::assertSame('12.345', $result); + } + + /** + * @throws ExceptionInterface + */ + public function testFloatValueDP2(): void + { + $result = app(FormatterServiceInterface::class)->floatValue('12345', 2); + + self::assertSame('123.45', $result); + } + + /** + * @throws ExceptionInterface + */ + public function testIntValueDP3(): void + { + $result = app(FormatterServiceInterface::class)->intValue('12.345', 3); + + self::assertSame('12345', $result); + } + + /** + * @throws ExceptionInterface + */ + public function testIntValueDP2(): void + { + $result = app(FormatterServiceInterface::class)->intValue('123.45', 2); + + self::assertSame('12345', $result); + } +} From d8c2ad8794fd155283a40e080071fb7d36d979fd Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 12:49:38 +0300 Subject: [PATCH 14/21] rector fix --- rector.php | 2 +- src/External/Api/TransactionQuery.php | 14 ++++++------ src/External/Api/TransactionQueryHandler.php | 10 ++++----- src/External/Api/TransferQuery.php | 10 ++++----- src/External/Api/TransferQueryHandler.php | 10 ++++----- src/External/Dto/Option.php | 8 +++---- .../BalanceUpdatedEventAssembler.php | 4 ++-- src/Internal/Assembler/ExtraDtoAssembler.php | 4 ++-- .../TransactionCreatedEventAssembler.php | 4 ++-- .../Assembler/TransactionDtoAssembler.php | 4 ++-- .../Assembler/TransferDtoAssembler.php | 4 ++-- .../Assembler/WalletCreatedEventAssembler.php | 4 ++-- .../Decorator/StorageServiceLockDecorator.php | 10 ++++----- src/Internal/Dto/AvailabilityDto.php | 8 +++---- src/Internal/Dto/BasketDto.php | 6 ++--- src/Internal/Dto/ItemDto.php | 10 ++++----- src/Internal/Dto/TransactionDto.php | 22 +++++++++---------- src/Internal/Dto/TransferDto.php | 22 +++++++++---------- src/Internal/Dto/TransferLazyDto.php | 18 +++++++-------- src/Internal/Events/BalanceUpdatedEvent.php | 10 ++++----- .../Events/TransactionCreatedEvent.php | 10 ++++----- src/Internal/Events/WalletCreatedEvent.php | 12 +++++----- src/Internal/Observers/TransferObserver.php | 4 ++-- src/Internal/Query/TransactionQuery.php | 4 ++-- src/Internal/Query/TransferQuery.php | 4 ++-- .../Repository/TransactionRepository.php | 8 +++---- .../Repository/TransferRepository.php | 6 ++--- src/Internal/Repository/WalletRepository.php | 4 ++-- src/Internal/Service/DatabaseService.php | 4 ++-- src/Internal/Service/MathService.php | 4 ++-- src/Internal/Service/StorageService.php | 8 +++---- src/Internal/Service/TranslatorService.php | 4 ++-- src/Internal/Service/UuidFactoryService.php | 4 ++-- src/Services/AssistantService.php | 6 ++--- src/Services/AtmService.php | 12 +++++----- src/Services/AtomicService.php | 12 +++++----- src/Services/BookkeeperService.php | 6 ++--- src/Services/CastService.php | 8 +++---- src/Services/ConsistencyService.php | 8 +++---- src/Services/EagerLoaderService.php | 6 ++--- src/Services/FormatterService.php | 3 +++ src/Services/FormatterServiceInterface.php | 2 +- src/Services/PrepareService.php | 18 +++++++-------- src/Services/PurchaseService.php | 4 ++-- src/Services/TaxService.php | 6 ++--- src/Services/TransactionService.php | 16 +++++++------- src/Services/TransferService.php | 14 ++++++------ src/Services/WalletService.php | 10 ++++----- .../TransactionDtoTransformerCustom.php | 4 ++-- 49 files changed, 199 insertions(+), 196 deletions(-) diff --git a/rector.php b/rector.php index 2713dfdc7..945b1ac02 100644 --- a/rector.php +++ b/rector.php @@ -18,5 +18,5 @@ $config->import(PHPUnitSetList::PHPUNIT_100); $config->import(SetList::CODE_QUALITY); $config->import(SetList::DEAD_CODE); - $config->import(SetList::PHP_81); + $config->import(SetList::PHP_82); }; diff --git a/src/External/Api/TransactionQuery.php b/src/External/Api/TransactionQuery.php index 3d1654a5c..08659160b 100644 --- a/src/External/Api/TransactionQuery.php +++ b/src/External/Api/TransactionQuery.php @@ -7,7 +7,7 @@ use Bavix\Wallet\Interfaces\Wallet; use Bavix\Wallet\Models\Transaction; -final class TransactionQuery +final readonly class TransactionQuery { public const TYPE_DEPOSIT = Transaction::TYPE_DEPOSIT; @@ -18,12 +18,12 @@ final class TransactionQuery * @param array|null $meta */ private function __construct( - private readonly string $type, - private readonly Wallet $wallet, - private readonly float|int|string $amount, - private readonly ?array $meta, - private readonly bool $confirmed, - private readonly ?string $uuid + private string $type, + private Wallet $wallet, + private float|int|string $amount, + private ?array $meta, + private bool $confirmed, + private ?string $uuid ) { } diff --git a/src/External/Api/TransactionQueryHandler.php b/src/External/Api/TransactionQueryHandler.php index 13f6786f2..5df4a661f 100644 --- a/src/External/Api/TransactionQueryHandler.php +++ b/src/External/Api/TransactionQueryHandler.php @@ -13,13 +13,13 @@ /** * @internal */ -final class TransactionQueryHandler implements TransactionQueryHandlerInterface +final readonly class TransactionQueryHandler implements TransactionQueryHandlerInterface { public function __construct( - private readonly TransactionServiceInterface $transactionService, - private readonly AssistantServiceInterface $assistantService, - private readonly PrepareServiceInterface $prepareService, - private readonly AtomicServiceInterface $atomicService + private TransactionServiceInterface $transactionService, + private AssistantServiceInterface $assistantService, + private PrepareServiceInterface $prepareService, + private AtomicServiceInterface $atomicService ) { } diff --git a/src/External/Api/TransferQuery.php b/src/External/Api/TransferQuery.php index a13b99149..aeba1e501 100644 --- a/src/External/Api/TransferQuery.php +++ b/src/External/Api/TransferQuery.php @@ -7,16 +7,16 @@ use Bavix\Wallet\External\Contracts\ExtraDtoInterface; use Bavix\Wallet\Interfaces\Wallet; -final class TransferQuery +final readonly class TransferQuery { /** * @param array|ExtraDtoInterface|null $meta */ public function __construct( - private readonly Wallet $from, - private readonly Wallet $to, - private readonly float|int|string $amount, - private readonly array|ExtraDtoInterface|null $meta + private Wallet $from, + private Wallet $to, + private float|int|string $amount, + private array|ExtraDtoInterface|null $meta ) { } diff --git a/src/External/Api/TransferQueryHandler.php b/src/External/Api/TransferQueryHandler.php index 156355581..51d72ea95 100644 --- a/src/External/Api/TransferQueryHandler.php +++ b/src/External/Api/TransferQueryHandler.php @@ -14,13 +14,13 @@ /** * @internal */ -final class TransferQueryHandler implements TransferQueryHandlerInterface +final readonly class TransferQueryHandler implements TransferQueryHandlerInterface { public function __construct( - private readonly AssistantServiceInterface $assistantService, - private readonly TransferServiceInterface $transferService, - private readonly PrepareServiceInterface $prepareService, - private readonly AtomicServiceInterface $atomicService + private AssistantServiceInterface $assistantService, + private TransferServiceInterface $transferService, + private PrepareServiceInterface $prepareService, + private AtomicServiceInterface $atomicService ) { } diff --git a/src/External/Dto/Option.php b/src/External/Dto/Option.php index 020ab8a4c..801f186f9 100644 --- a/src/External/Dto/Option.php +++ b/src/External/Dto/Option.php @@ -6,15 +6,15 @@ use Bavix\Wallet\External\Contracts\OptionDtoInterface; -final class Option implements OptionDtoInterface +final readonly class Option implements OptionDtoInterface { /** * @param null|array $meta */ public function __construct( - private readonly ?array $meta, - private readonly bool $confirmed = true, - private readonly ?string $uuid = null + private ?array $meta, + private bool $confirmed = true, + private ?string $uuid = null ) { } diff --git a/src/Internal/Assembler/BalanceUpdatedEventAssembler.php b/src/Internal/Assembler/BalanceUpdatedEventAssembler.php index 2a423a851..fe1affae8 100644 --- a/src/Internal/Assembler/BalanceUpdatedEventAssembler.php +++ b/src/Internal/Assembler/BalanceUpdatedEventAssembler.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Internal\Service\ClockServiceInterface; use Bavix\Wallet\Models\Wallet; -final class BalanceUpdatedEventAssembler implements BalanceUpdatedEventAssemblerInterface +final readonly class BalanceUpdatedEventAssembler implements BalanceUpdatedEventAssemblerInterface { public function __construct( - private readonly ClockServiceInterface $clockService + private ClockServiceInterface $clockService ) { } diff --git a/src/Internal/Assembler/ExtraDtoAssembler.php b/src/Internal/Assembler/ExtraDtoAssembler.php index c5aaf64d3..fa28896f0 100644 --- a/src/Internal/Assembler/ExtraDtoAssembler.php +++ b/src/Internal/Assembler/ExtraDtoAssembler.php @@ -7,10 +7,10 @@ use Bavix\Wallet\External\Contracts\ExtraDtoInterface; use Bavix\Wallet\External\Dto\Extra; -final class ExtraDtoAssembler implements ExtraDtoAssemblerInterface +final readonly class ExtraDtoAssembler implements ExtraDtoAssemblerInterface { public function __construct( - private readonly OptionDtoAssemblerInterface $optionDtoAssembler + private OptionDtoAssemblerInterface $optionDtoAssembler ) { } diff --git a/src/Internal/Assembler/TransactionCreatedEventAssembler.php b/src/Internal/Assembler/TransactionCreatedEventAssembler.php index a2783b580..c37ccb921 100644 --- a/src/Internal/Assembler/TransactionCreatedEventAssembler.php +++ b/src/Internal/Assembler/TransactionCreatedEventAssembler.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Internal\Service\ClockServiceInterface; use Bavix\Wallet\Models\Transaction; -final class TransactionCreatedEventAssembler implements TransactionCreatedEventAssemblerInterface +final readonly class TransactionCreatedEventAssembler implements TransactionCreatedEventAssemblerInterface { public function __construct( - private readonly ClockServiceInterface $clockService + private ClockServiceInterface $clockService ) { } diff --git a/src/Internal/Assembler/TransactionDtoAssembler.php b/src/Internal/Assembler/TransactionDtoAssembler.php index 1279e4cde..e183d60c3 100644 --- a/src/Internal/Assembler/TransactionDtoAssembler.php +++ b/src/Internal/Assembler/TransactionDtoAssembler.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Illuminate\Database\Eloquent\Model; -final class TransactionDtoAssembler implements TransactionDtoAssemblerInterface +final readonly class TransactionDtoAssembler implements TransactionDtoAssemblerInterface { public function __construct( - private readonly UuidFactoryServiceInterface $uuidService + private UuidFactoryServiceInterface $uuidService ) { } diff --git a/src/Internal/Assembler/TransferDtoAssembler.php b/src/Internal/Assembler/TransferDtoAssembler.php index 0f2f804fd..280580f3b 100644 --- a/src/Internal/Assembler/TransferDtoAssembler.php +++ b/src/Internal/Assembler/TransferDtoAssembler.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Illuminate\Database\Eloquent\Model; -final class TransferDtoAssembler implements TransferDtoAssemblerInterface +final readonly class TransferDtoAssembler implements TransferDtoAssemblerInterface { public function __construct( - private readonly UuidFactoryServiceInterface $uuidService + private UuidFactoryServiceInterface $uuidService ) { } diff --git a/src/Internal/Assembler/WalletCreatedEventAssembler.php b/src/Internal/Assembler/WalletCreatedEventAssembler.php index 5c1b8a90c..86eadd2e1 100644 --- a/src/Internal/Assembler/WalletCreatedEventAssembler.php +++ b/src/Internal/Assembler/WalletCreatedEventAssembler.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Internal\Service\ClockServiceInterface; use Bavix\Wallet\Models\Wallet; -final class WalletCreatedEventAssembler implements WalletCreatedEventAssemblerInterface +final readonly class WalletCreatedEventAssembler implements WalletCreatedEventAssemblerInterface { public function __construct( - private readonly ClockServiceInterface $clockService + private ClockServiceInterface $clockService ) { } diff --git a/src/Internal/Decorator/StorageServiceLockDecorator.php b/src/Internal/Decorator/StorageServiceLockDecorator.php index 699519529..1e4c449c3 100644 --- a/src/Internal/Decorator/StorageServiceLockDecorator.php +++ b/src/Internal/Decorator/StorageServiceLockDecorator.php @@ -10,13 +10,13 @@ use Bavix\Wallet\Internal\Service\StateServiceInterface; use Bavix\Wallet\Internal\Service\StorageServiceInterface; -final class StorageServiceLockDecorator implements StorageServiceInterface +final readonly class StorageServiceLockDecorator implements StorageServiceInterface { public function __construct( - private readonly StorageServiceInterface $storageService, - private readonly StateServiceInterface $stateService, - private readonly LockServiceInterface $lockService, - private readonly MathServiceInterface $mathService + private StorageServiceInterface $storageService, + private StateServiceInterface $stateService, + private LockServiceInterface $lockService, + private MathServiceInterface $mathService ) { } diff --git a/src/Internal/Dto/AvailabilityDto.php b/src/Internal/Dto/AvailabilityDto.php index e1406654d..af4ffbfc4 100644 --- a/src/Internal/Dto/AvailabilityDto.php +++ b/src/Internal/Dto/AvailabilityDto.php @@ -7,12 +7,12 @@ use Bavix\Wallet\Interfaces\Customer; /** @immutable */ -final class AvailabilityDto implements AvailabilityDtoInterface +final readonly class AvailabilityDto implements AvailabilityDtoInterface { public function __construct( - private readonly Customer $customer, - private readonly BasketDtoInterface $basketDto, - private readonly bool $force + private Customer $customer, + private BasketDtoInterface $basketDto, + private bool $force ) { } diff --git a/src/Internal/Dto/BasketDto.php b/src/Internal/Dto/BasketDto.php index 6191cc4e9..22b605461 100644 --- a/src/Internal/Dto/BasketDto.php +++ b/src/Internal/Dto/BasketDto.php @@ -7,15 +7,15 @@ use Bavix\Wallet\Interfaces\ProductInterface; use Generator; -final class BasketDto implements BasketDtoInterface +final readonly class BasketDto implements BasketDtoInterface { /** * @param non-empty-array $items * @param array $meta */ public function __construct( - private readonly array $items, - private readonly array $meta + private array $items, + private array $meta ) { } diff --git a/src/Internal/Dto/ItemDto.php b/src/Internal/Dto/ItemDto.php index 94f23d2b4..4af3c87f0 100644 --- a/src/Internal/Dto/ItemDto.php +++ b/src/Internal/Dto/ItemDto.php @@ -8,13 +8,13 @@ use Bavix\Wallet\Interfaces\Wallet; /** @immutable */ -final class ItemDto implements ItemDtoInterface +final readonly class ItemDto implements ItemDtoInterface { public function __construct( - private readonly ProductInterface $product, - private readonly int $quantity, - private readonly int|string|null $pricePerItem, - private readonly ?Wallet $receiving, + private ProductInterface $product, + private int $quantity, + private int|string|null $pricePerItem, + private ?Wallet $receiving, ) { } diff --git a/src/Internal/Dto/TransactionDto.php b/src/Internal/Dto/TransactionDto.php index a32431f47..f74d5aeec 100644 --- a/src/Internal/Dto/TransactionDto.php +++ b/src/Internal/Dto/TransactionDto.php @@ -7,24 +7,24 @@ use DateTimeImmutable; /** @immutable */ -final class TransactionDto implements TransactionDtoInterface +final readonly class TransactionDto implements TransactionDtoInterface { - private readonly DateTimeImmutable $createdAt; + private DateTimeImmutable $createdAt; - private readonly DateTimeImmutable $updatedAt; + private DateTimeImmutable $updatedAt; /** * @param array|null $meta */ public function __construct( - private readonly string $uuid, - private readonly string $payableType, - private readonly int|string $payableId, - private readonly int $walletId, - private readonly string $type, - private readonly float|int|string $amount, - private readonly bool $confirmed, - private readonly ?array $meta + private string $uuid, + private string $payableType, + private int|string $payableId, + private int $walletId, + private string $type, + private float|int|string $amount, + private bool $confirmed, + private ?array $meta ) { $this->createdAt = new DateTimeImmutable(); $this->updatedAt = new DateTimeImmutable(); diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index f50f1b748..0d408a82b 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -7,21 +7,21 @@ use DateTimeImmutable; /** @immutable */ -final class TransferDto implements TransferDtoInterface +final readonly class TransferDto implements TransferDtoInterface { - private readonly DateTimeImmutable $createdAt; + private DateTimeImmutable $createdAt; - private readonly DateTimeImmutable $updatedAt; + private DateTimeImmutable $updatedAt; public function __construct( - private readonly string $uuid, - private readonly int $depositId, - private readonly int $withdrawId, - private readonly string $status, - private readonly int|string $fromId, - private readonly int|string $toId, - private readonly int $discount, - private readonly string $fee + private string $uuid, + private int $depositId, + private int $withdrawId, + private string $status, + private int|string $fromId, + private int|string $toId, + private int $discount, + private string $fee ) { $this->createdAt = new DateTimeImmutable(); $this->updatedAt = new DateTimeImmutable(); diff --git a/src/Internal/Dto/TransferLazyDto.php b/src/Internal/Dto/TransferLazyDto.php index f52f1c32b..c0332479e 100644 --- a/src/Internal/Dto/TransferLazyDto.php +++ b/src/Internal/Dto/TransferLazyDto.php @@ -7,17 +7,17 @@ use Bavix\Wallet\Interfaces\Wallet; /** @immutable */ -final class TransferLazyDto implements TransferLazyDtoInterface +final readonly class TransferLazyDto implements TransferLazyDtoInterface { public function __construct( - private readonly Wallet $fromWallet, - private readonly Wallet $toWallet, - private readonly int $discount, - private readonly string $fee, - private readonly TransactionDtoInterface $withdrawDto, - private readonly TransactionDtoInterface $depositDto, - private readonly string $status, - private readonly ?string $uuid + private Wallet $fromWallet, + private Wallet $toWallet, + private int $discount, + private string $fee, + private TransactionDtoInterface $withdrawDto, + private TransactionDtoInterface $depositDto, + private string $status, + private ?string $uuid ) { } diff --git a/src/Internal/Events/BalanceUpdatedEvent.php b/src/Internal/Events/BalanceUpdatedEvent.php index 394ab4b42..622f5905e 100644 --- a/src/Internal/Events/BalanceUpdatedEvent.php +++ b/src/Internal/Events/BalanceUpdatedEvent.php @@ -6,13 +6,13 @@ use DateTimeImmutable; -final class BalanceUpdatedEvent implements BalanceUpdatedEventInterface +final readonly class BalanceUpdatedEvent implements BalanceUpdatedEventInterface { public function __construct( - private readonly int $walletId, - private readonly string $walletUuid, - private readonly string $balance, - private readonly DateTimeImmutable $updatedAt + private int $walletId, + private string $walletUuid, + private string $balance, + private DateTimeImmutable $updatedAt ) { } diff --git a/src/Internal/Events/TransactionCreatedEvent.php b/src/Internal/Events/TransactionCreatedEvent.php index c4889e5f5..967be068d 100644 --- a/src/Internal/Events/TransactionCreatedEvent.php +++ b/src/Internal/Events/TransactionCreatedEvent.php @@ -6,13 +6,13 @@ use DateTimeImmutable; -final class TransactionCreatedEvent implements TransactionCreatedEventInterface +final readonly class TransactionCreatedEvent implements TransactionCreatedEventInterface { public function __construct( - private readonly int $id, - private readonly string $type, - private readonly int $walletId, - private readonly DateTimeImmutable $createdAt, + private int $id, + private string $type, + private int $walletId, + private DateTimeImmutable $createdAt, ) { } diff --git a/src/Internal/Events/WalletCreatedEvent.php b/src/Internal/Events/WalletCreatedEvent.php index b6ecc1808..30c1910e5 100644 --- a/src/Internal/Events/WalletCreatedEvent.php +++ b/src/Internal/Events/WalletCreatedEvent.php @@ -6,14 +6,14 @@ use DateTimeImmutable; -final class WalletCreatedEvent implements WalletCreatedEventInterface +final readonly class WalletCreatedEvent implements WalletCreatedEventInterface { public function __construct( - private readonly string $holderType, - private readonly int|string $holderId, - private readonly string $walletUuid, - private readonly int $walletId, - private readonly DateTimeImmutable $createdAt + private string $holderType, + private int|string $holderId, + private string $walletUuid, + private int $walletId, + private DateTimeImmutable $createdAt ) { } diff --git a/src/Internal/Observers/TransferObserver.php b/src/Internal/Observers/TransferObserver.php index ec1bdee78..136670302 100644 --- a/src/Internal/Observers/TransferObserver.php +++ b/src/Internal/Observers/TransferObserver.php @@ -13,10 +13,10 @@ use Bavix\Wallet\Services\AtomicServiceInterface; use Illuminate\Database\RecordsNotFoundException; -final class TransferObserver +final readonly class TransferObserver { public function __construct( - private readonly AtomicServiceInterface $atomicService + private AtomicServiceInterface $atomicService ) { } diff --git a/src/Internal/Query/TransactionQuery.php b/src/Internal/Query/TransactionQuery.php index db2cfac9f..51ab135fc 100644 --- a/src/Internal/Query/TransactionQuery.php +++ b/src/Internal/Query/TransactionQuery.php @@ -8,13 +8,13 @@ * @immutable * @internal */ -final class TransactionQuery implements TransactionQueryInterface +final readonly class TransactionQuery implements TransactionQueryInterface { /** * @param non-empty-array $uuids */ public function __construct( - private readonly array $uuids + private array $uuids ) { } diff --git a/src/Internal/Query/TransferQuery.php b/src/Internal/Query/TransferQuery.php index e4cd6e663..3486a266e 100644 --- a/src/Internal/Query/TransferQuery.php +++ b/src/Internal/Query/TransferQuery.php @@ -8,13 +8,13 @@ * @immutable * @internal */ -final class TransferQuery implements TransferQueryInterface +final readonly class TransferQuery implements TransferQueryInterface { /** * @param non-empty-array $uuids */ public function __construct( - private readonly array $uuids + private array $uuids ) { } diff --git a/src/Internal/Repository/TransactionRepository.php b/src/Internal/Repository/TransactionRepository.php index 9f2246a51..185fd415f 100644 --- a/src/Internal/Repository/TransactionRepository.php +++ b/src/Internal/Repository/TransactionRepository.php @@ -10,12 +10,12 @@ use Bavix\Wallet\Internal\Transform\TransactionDtoTransformerInterface; use Bavix\Wallet\Models\Transaction; -final class TransactionRepository implements TransactionRepositoryInterface +final readonly class TransactionRepository implements TransactionRepositoryInterface { public function __construct( - private readonly TransactionDtoTransformerInterface $transformer, - private readonly JsonServiceInterface $jsonService, - private readonly Transaction $transaction + private TransactionDtoTransformerInterface $transformer, + private JsonServiceInterface $jsonService, + private Transaction $transaction ) { } diff --git a/src/Internal/Repository/TransferRepository.php b/src/Internal/Repository/TransferRepository.php index 6e982f1fe..b89bcb0e3 100644 --- a/src/Internal/Repository/TransferRepository.php +++ b/src/Internal/Repository/TransferRepository.php @@ -9,11 +9,11 @@ use Bavix\Wallet\Internal\Transform\TransferDtoTransformerInterface; use Bavix\Wallet\Models\Transfer; -final class TransferRepository implements TransferRepositoryInterface +final readonly class TransferRepository implements TransferRepositoryInterface { public function __construct( - private readonly TransferDtoTransformerInterface $transformer, - private readonly Transfer $transfer + private TransferDtoTransformerInterface $transformer, + private Transfer $transfer ) { } diff --git a/src/Internal/Repository/WalletRepository.php b/src/Internal/Repository/WalletRepository.php index a01165b77..893889ef8 100644 --- a/src/Internal/Repository/WalletRepository.php +++ b/src/Internal/Repository/WalletRepository.php @@ -9,10 +9,10 @@ use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Eloquent\ModelNotFoundException as EloquentModelNotFoundException; -final class WalletRepository implements WalletRepositoryInterface +final readonly class WalletRepository implements WalletRepositoryInterface { public function __construct( - private readonly Wallet $wallet + private Wallet $wallet ) { } diff --git a/src/Internal/Service/DatabaseService.php b/src/Internal/Service/DatabaseService.php index ab6852f0e..c64d591c7 100644 --- a/src/Internal/Service/DatabaseService.php +++ b/src/Internal/Service/DatabaseService.php @@ -10,10 +10,10 @@ use Illuminate\Database\RecordsNotFoundException; use Throwable; -final class DatabaseService implements DatabaseServiceInterface +final readonly class DatabaseService implements DatabaseServiceInterface { public function __construct( - private readonly ConnectionServiceInterface $connectionService + private ConnectionServiceInterface $connectionService ) { } diff --git a/src/Internal/Service/MathService.php b/src/Internal/Service/MathService.php index 8ce6e90d2..55680f139 100644 --- a/src/Internal/Service/MathService.php +++ b/src/Internal/Service/MathService.php @@ -7,10 +7,10 @@ use Brick\Math\BigDecimal; use Brick\Math\RoundingMode; -final class MathService implements MathServiceInterface +final readonly class MathService implements MathServiceInterface { public function __construct( - private readonly int $scale + private int $scale ) { } diff --git a/src/Internal/Service/StorageService.php b/src/Internal/Service/StorageService.php index b1181b731..97bf2b952 100644 --- a/src/Internal/Service/StorageService.php +++ b/src/Internal/Service/StorageService.php @@ -8,14 +8,14 @@ use Bavix\Wallet\Internal\Exceptions\RecordNotFoundException; use Illuminate\Contracts\Cache\Repository as CacheRepository; -final class StorageService implements StorageServiceInterface +final readonly class StorageService implements StorageServiceInterface { private const PREFIX = 'wallet_sg::'; public function __construct( - private readonly MathServiceInterface $mathService, - private readonly CacheRepository $cacheRepository, - private readonly ?int $ttl + private MathServiceInterface $mathService, + private CacheRepository $cacheRepository, + private ?int $ttl ) { } diff --git a/src/Internal/Service/TranslatorService.php b/src/Internal/Service/TranslatorService.php index 9fac67f89..76b41f9a2 100644 --- a/src/Internal/Service/TranslatorService.php +++ b/src/Internal/Service/TranslatorService.php @@ -6,10 +6,10 @@ use Illuminate\Contracts\Translation\Translator; -final class TranslatorService implements TranslatorServiceInterface +final readonly class TranslatorService implements TranslatorServiceInterface { public function __construct( - private readonly Translator $translator + private Translator $translator ) { } diff --git a/src/Internal/Service/UuidFactoryService.php b/src/Internal/Service/UuidFactoryService.php index e672b5d18..e08329e7b 100644 --- a/src/Internal/Service/UuidFactoryService.php +++ b/src/Internal/Service/UuidFactoryService.php @@ -6,10 +6,10 @@ use Ramsey\Uuid\UuidFactory; -final class UuidFactoryService implements UuidFactoryServiceInterface +final readonly class UuidFactoryService implements UuidFactoryServiceInterface { public function __construct( - private readonly UuidFactory $uuidFactory + private UuidFactory $uuidFactory ) { } diff --git a/src/Services/AssistantService.php b/src/Services/AssistantService.php index d2f152fdb..4c8f7a29a 100644 --- a/src/Services/AssistantService.php +++ b/src/Services/AssistantService.php @@ -14,11 +14,11 @@ /** * @internal */ -final class AssistantService implements AssistantServiceInterface +final readonly class AssistantService implements AssistantServiceInterface { public function __construct( - private readonly CastServiceInterface $castService, - private readonly MathServiceInterface $mathService + private CastServiceInterface $castService, + private MathServiceInterface $mathService ) { } diff --git a/src/Services/AtmService.php b/src/Services/AtmService.php index 84ee2de37..4861dd569 100644 --- a/src/Services/AtmService.php +++ b/src/Services/AtmService.php @@ -16,14 +16,14 @@ /** * @internal */ -final class AtmService implements AtmServiceInterface +final readonly class AtmService implements AtmServiceInterface { public function __construct( - private readonly TransactionQueryAssemblerInterface $transactionQueryAssembler, - private readonly TransferQueryAssemblerInterface $transferQueryAssembler, - private readonly TransactionRepositoryInterface $transactionRepository, - private readonly TransferRepositoryInterface $transferRepository, - private readonly AssistantServiceInterface $assistantService + private TransactionQueryAssemblerInterface $transactionQueryAssembler, + private TransferQueryAssemblerInterface $transferQueryAssembler, + private TransactionRepositoryInterface $transactionRepository, + private TransferRepositoryInterface $transferRepository, + private AssistantServiceInterface $assistantService ) { } diff --git a/src/Services/AtomicService.php b/src/Services/AtomicService.php index de498e9a9..02c074ba7 100644 --- a/src/Services/AtomicService.php +++ b/src/Services/AtomicService.php @@ -15,14 +15,14 @@ /** * @internal */ -final class AtomicService implements AtomicServiceInterface +final readonly class AtomicService implements AtomicServiceInterface { public function __construct( - private readonly BookkeeperServiceInterface $bookkeeperService, - private readonly DatabaseServiceInterface $databaseService, - private readonly StateServiceInterface $stateService, - private readonly LockServiceInterface $lockService, - private readonly CastServiceInterface $castService + private BookkeeperServiceInterface $bookkeeperService, + private DatabaseServiceInterface $databaseService, + private StateServiceInterface $stateService, + private LockServiceInterface $lockService, + private CastServiceInterface $castService ) { } diff --git a/src/Services/BookkeeperService.php b/src/Services/BookkeeperService.php index 2eb53cf40..558ed155b 100644 --- a/src/Services/BookkeeperService.php +++ b/src/Services/BookkeeperService.php @@ -12,11 +12,11 @@ /** * @internal */ -final class BookkeeperService implements BookkeeperServiceInterface +final readonly class BookkeeperService implements BookkeeperServiceInterface { public function __construct( - private readonly StorageServiceInterface $storageService, - private readonly LockServiceInterface $lockService + private StorageServiceInterface $storageService, + private LockServiceInterface $lockService ) { } diff --git a/src/Services/CastService.php b/src/Services/CastService.php index 8ffe36f0b..80ed50d53 100644 --- a/src/Services/CastService.php +++ b/src/Services/CastService.php @@ -15,12 +15,12 @@ /** * @internal */ -final class CastService implements CastServiceInterface +final readonly class CastService implements CastServiceInterface { public function __construct( - private readonly WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, - private readonly DispatcherServiceInterface $dispatcherService, - private readonly DatabaseServiceInterface $databaseService + private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, + private DispatcherServiceInterface $dispatcherService, + private DatabaseServiceInterface $databaseService ) { } diff --git a/src/Services/ConsistencyService.php b/src/Services/ConsistencyService.php index 30762b192..92f3c9334 100644 --- a/src/Services/ConsistencyService.php +++ b/src/Services/ConsistencyService.php @@ -16,12 +16,12 @@ /** * @internal */ -final class ConsistencyService implements ConsistencyServiceInterface +final readonly class ConsistencyService implements ConsistencyServiceInterface { public function __construct( - private readonly TranslatorServiceInterface $translatorService, - private readonly MathServiceInterface $mathService, - private readonly CastServiceInterface $castService + private TranslatorServiceInterface $translatorService, + private MathServiceInterface $mathService, + private CastServiceInterface $castService ) { } diff --git a/src/Services/EagerLoaderService.php b/src/Services/EagerLoaderService.php index 4303d7b9b..e947695a3 100644 --- a/src/Services/EagerLoaderService.php +++ b/src/Services/EagerLoaderService.php @@ -12,11 +12,11 @@ /** * @internal */ -final class EagerLoaderService implements EagerLoaderServiceInterface +final readonly class EagerLoaderService implements EagerLoaderServiceInterface { public function __construct( - private readonly CastServiceInterface $castService, - private readonly WalletRepositoryInterface $walletRepository + private CastServiceInterface $castService, + private WalletRepositoryInterface $walletRepository ) { } diff --git a/src/Services/FormatterService.php b/src/Services/FormatterService.php index b078cfd14..0adbeff8a 100644 --- a/src/Services/FormatterService.php +++ b/src/Services/FormatterService.php @@ -7,6 +7,9 @@ use Brick\Math\BigDecimal; use Brick\Math\RoundingMode; +/** + * @internal + */ final readonly class FormatterService implements FormatterServiceInterface { public function intValue(string|int|float $amount, int $decimalPlaces): string diff --git a/src/Services/FormatterServiceInterface.php b/src/Services/FormatterServiceInterface.php index e2d8eee2f..1b1ff1767 100644 --- a/src/Services/FormatterServiceInterface.php +++ b/src/Services/FormatterServiceInterface.php @@ -5,7 +5,7 @@ namespace Bavix\Wallet\Services; /** - * @internal + * @api */ interface FormatterServiceInterface { diff --git a/src/Services/PrepareService.php b/src/Services/PrepareService.php index e38d87051..55379ae66 100644 --- a/src/Services/PrepareService.php +++ b/src/Services/PrepareService.php @@ -19,17 +19,17 @@ /** * @internal */ -final class PrepareService implements PrepareServiceInterface +final readonly class PrepareService implements PrepareServiceInterface { public function __construct( - private readonly TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler, - private readonly TransactionDtoAssemblerInterface $transactionDtoAssembler, - private readonly DiscountServiceInterface $personalDiscountService, - private readonly ConsistencyServiceInterface $consistencyService, - private readonly ExtraDtoAssemblerInterface $extraDtoAssembler, - private readonly CastServiceInterface $castService, - private readonly MathServiceInterface $mathService, - private readonly TaxServiceInterface $taxService + private TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler, + private TransactionDtoAssemblerInterface $transactionDtoAssembler, + private DiscountServiceInterface $personalDiscountService, + private ConsistencyServiceInterface $consistencyService, + private ExtraDtoAssemblerInterface $extraDtoAssembler, + private CastServiceInterface $castService, + private MathServiceInterface $mathService, + private TaxServiceInterface $taxService ) { } diff --git a/src/Services/PurchaseService.php b/src/Services/PurchaseService.php index 0b5405b19..bb18499c3 100644 --- a/src/Services/PurchaseService.php +++ b/src/Services/PurchaseService.php @@ -11,10 +11,10 @@ /** * @internal */ -final class PurchaseService implements PurchaseServiceInterface +final readonly class PurchaseService implements PurchaseServiceInterface { public function __construct( - private readonly CastServiceInterface $castService + private CastServiceInterface $castService ) { } diff --git a/src/Services/TaxService.php b/src/Services/TaxService.php index 6e527d8fe..adcb3175e 100644 --- a/src/Services/TaxService.php +++ b/src/Services/TaxService.php @@ -13,11 +13,11 @@ /** * @internal */ -final class TaxService implements TaxServiceInterface +final readonly class TaxService implements TaxServiceInterface { public function __construct( - private readonly MathServiceInterface $mathService, - private readonly CastServiceInterface $castService + private MathServiceInterface $mathService, + private CastServiceInterface $castService ) { } diff --git a/src/Services/TransactionService.php b/src/Services/TransactionService.php index 178adf2c9..c5b43d081 100644 --- a/src/Services/TransactionService.php +++ b/src/Services/TransactionService.php @@ -14,16 +14,16 @@ /** * @internal */ -final class TransactionService implements TransactionServiceInterface +final readonly class TransactionService implements TransactionServiceInterface { public function __construct( - private readonly TransactionCreatedEventAssemblerInterface $transactionCreatedEventAssembler, - private readonly DispatcherServiceInterface $dispatcherService, - private readonly AssistantServiceInterface $assistantService, - private readonly RegulatorServiceInterface $regulatorService, - private readonly PrepareServiceInterface $prepareService, - private readonly CastServiceInterface $castService, - private readonly AtmServiceInterface $atmService, + private TransactionCreatedEventAssemblerInterface $transactionCreatedEventAssembler, + private DispatcherServiceInterface $dispatcherService, + private AssistantServiceInterface $assistantService, + private RegulatorServiceInterface $regulatorService, + private PrepareServiceInterface $prepareService, + private CastServiceInterface $castService, + private AtmServiceInterface $atmService, ) { } diff --git a/src/Services/TransferService.php b/src/Services/TransferService.php index fa98b710b..18ede128a 100644 --- a/src/Services/TransferService.php +++ b/src/Services/TransferService.php @@ -18,15 +18,15 @@ /** * @internal */ -final class TransferService implements TransferServiceInterface +final readonly class TransferService implements TransferServiceInterface { public function __construct( - private readonly TransferDtoAssemblerInterface $transferDtoAssembler, - private readonly TransferRepositoryInterface $transferRepository, - private readonly TransactionServiceInterface $transactionService, - private readonly DatabaseServiceInterface $databaseService, - private readonly CastServiceInterface $castService, - private readonly AtmServiceInterface $atmService, + private TransferDtoAssemblerInterface $transferDtoAssembler, + private TransferRepositoryInterface $transferRepository, + private TransactionServiceInterface $transactionService, + private DatabaseServiceInterface $databaseService, + private CastServiceInterface $castService, + private AtmServiceInterface $atmService, ) { } diff --git a/src/Services/WalletService.php b/src/Services/WalletService.php index f2f34ba03..d33a072c9 100644 --- a/src/Services/WalletService.php +++ b/src/Services/WalletService.php @@ -15,13 +15,13 @@ /** * @internal */ -final class WalletService implements WalletServiceInterface +final readonly class WalletService implements WalletServiceInterface { public function __construct( - private readonly WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, - private readonly UuidFactoryServiceInterface $uuidFactoryService, - private readonly DispatcherServiceInterface $dispatcherService, - private readonly WalletRepositoryInterface $walletRepository + private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, + private UuidFactoryServiceInterface $uuidFactoryService, + private DispatcherServiceInterface $dispatcherService, + private WalletRepositoryInterface $walletRepository ) { } diff --git a/tests/Infra/Transform/TransactionDtoTransformerCustom.php b/tests/Infra/Transform/TransactionDtoTransformerCustom.php index 501f67368..6fe4e07d3 100644 --- a/tests/Infra/Transform/TransactionDtoTransformerCustom.php +++ b/tests/Infra/Transform/TransactionDtoTransformerCustom.php @@ -8,10 +8,10 @@ use Bavix\Wallet\Internal\Transform\TransactionDtoTransformer; use Bavix\Wallet\Internal\Transform\TransactionDtoTransformerInterface; -final class TransactionDtoTransformerCustom implements TransactionDtoTransformerInterface +final readonly class TransactionDtoTransformerCustom implements TransactionDtoTransformerInterface { public function __construct( - private readonly TransactionDtoTransformer $transactionDtoTransformer + private TransactionDtoTransformer $transactionDtoTransformer ) { } From 1d4a652155b52611d4b184d216168c028b4911b4 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 14:26:27 +0300 Subject: [PATCH 15/21] fix Qodana --- .github/workflows/code-quality.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 1e150b30a..81460f9ce 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -18,6 +18,30 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: bcmath + env: + runner: self-hosted + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2023.3 env: From f956ed0804330dddae5626a4e9d95e9574ff9bb0 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 17:54:33 +0300 Subject: [PATCH 16/21] technical debt --- phpstan.src.baseline.neon | 4 ++-- src/Internal/Dto/TransferDto.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpstan.src.baseline.neon b/phpstan.src.baseline.neon index 36daaf66c..2ce79eedd 100644 --- a/phpstan.src.baseline.neon +++ b/phpstan.src.baseline.neon @@ -21,12 +21,12 @@ parameters: path: src/Internal/Assembler/TransactionDtoAssembler.php - - message: "#^Parameter \\#5 \\$fromId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" + message: "#^Parameter \\#5 \\$fromId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int, mixed given\\.$#" count: 1 path: src/Internal/Assembler/TransferDtoAssembler.php - - message: "#^Parameter \\#6 \\$toId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int\\|string, mixed given\\.$#" + message: "#^Parameter \\#6 \\$toId of class Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto constructor expects int, mixed given\\.$#" count: 1 path: src/Internal/Assembler/TransferDtoAssembler.php diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index 0d408a82b..2f95d88d9 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -18,8 +18,8 @@ public function __construct( private int $depositId, private int $withdrawId, private string $status, - private int|string $fromId, - private int|string $toId, + private int $fromId, + private int $toId, private int $discount, private string $fee ) { From 48f82c9511353446efea7b525e586c156c1b15e5 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 17:59:12 +0300 Subject: [PATCH 17/21] add gmp-ext --- .github/workflows/code-quality.yaml | 2 +- .github/workflows/code-style.yaml | 2 +- .github/workflows/deptrac.yaml | 2 +- .github/workflows/phpstan.yaml | 2 +- .github/workflows/phpunits.yaml | 2 +- .github/workflows/rector.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 81460f9ce..320a22a47 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -23,7 +23,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath + extensions: bcmath, gmp env: runner: self-hosted diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml index cc0b1dd45..9394845b5 100644 --- a/.github/workflows/code-style.yaml +++ b/.github/workflows/code-style.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath + extensions: bcmath, gmp env: runner: self-hosted diff --git a/.github/workflows/deptrac.yaml b/.github/workflows/deptrac.yaml index 7ba02bba3..f1049e32a 100644 --- a/.github/workflows/deptrac.yaml +++ b/.github/workflows/deptrac.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath + extensions: bcmath, gmp env: runner: self-hosted diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index fdf50e299..ca6ce5452 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath + extensions: bcmath, gmp env: runner: self-hosted diff --git a/.github/workflows/phpunits.yaml b/.github/workflows/phpunits.yaml index 0fc8630d8..92e347e53 100644 --- a/.github/workflows/phpunits.yaml +++ b/.github/workflows/phpunits.yaml @@ -95,7 +95,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath + extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath, gmp coverage: pcov env: runner: self-hosted diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index d34ee97e7..0aea56656 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath + extensions: bcmath, gmp env: runner: self-hosted From 5f314795323a32bd4cca667960293a2a871633f4 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 19:06:22 +0300 Subject: [PATCH 18/21] Revert "add gmp-ext" This reverts commit 48f82c9511353446efea7b525e586c156c1b15e5. --- .github/workflows/code-quality.yaml | 2 +- .github/workflows/code-style.yaml | 2 +- .github/workflows/deptrac.yaml | 2 +- .github/workflows/phpstan.yaml | 2 +- .github/workflows/phpunits.yaml | 2 +- .github/workflows/rector.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 320a22a47..81460f9ce 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -23,7 +23,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath, gmp + extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml index 9394845b5..cc0b1dd45 100644 --- a/.github/workflows/code-style.yaml +++ b/.github/workflows/code-style.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath, gmp + extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/deptrac.yaml b/.github/workflows/deptrac.yaml index f1049e32a..7ba02bba3 100644 --- a/.github/workflows/deptrac.yaml +++ b/.github/workflows/deptrac.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath, gmp + extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index ca6ce5452..fdf50e299 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath, gmp + extensions: bcmath env: runner: self-hosted diff --git a/.github/workflows/phpunits.yaml b/.github/workflows/phpunits.yaml index 92e347e53..0fc8630d8 100644 --- a/.github/workflows/phpunits.yaml +++ b/.github/workflows/phpunits.yaml @@ -95,7 +95,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath, gmp + extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath coverage: pcov env: runner: self-hosted diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index 0aea56656..d34ee97e7 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -18,7 +18,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - extensions: bcmath, gmp + extensions: bcmath env: runner: self-hosted From 9579ffddab62a41f22e73fab85bee5861cb146f2 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 19:08:37 +0300 Subject: [PATCH 19/21] dto fix --- src/Internal/Assembler/TransactionDtoAssembler.php | 8 ++++++-- src/Internal/Assembler/TransferDtoAssembler.php | 8 ++++++-- src/Internal/Dto/TransactionDto.php | 10 +++------- src/Internal/Dto/TransferDto.php | 10 +++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Internal/Assembler/TransactionDtoAssembler.php b/src/Internal/Assembler/TransactionDtoAssembler.php index e183d60c3..93b0a6e4c 100644 --- a/src/Internal/Assembler/TransactionDtoAssembler.php +++ b/src/Internal/Assembler/TransactionDtoAssembler.php @@ -6,13 +6,15 @@ use Bavix\Wallet\Internal\Dto\TransactionDto; use Bavix\Wallet\Internal\Dto\TransactionDtoInterface; +use Bavix\Wallet\Internal\Service\ClockServiceInterface; use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Illuminate\Database\Eloquent\Model; final readonly class TransactionDtoAssembler implements TransactionDtoAssemblerInterface { public function __construct( - private UuidFactoryServiceInterface $uuidService + private UuidFactoryServiceInterface $uuidService, + private ClockServiceInterface $clockService, ) { } @@ -33,7 +35,9 @@ public function create( $type, $amount, $confirmed, - $meta + $meta, + $this->clockService->now(), + $this->clockService->now(), ); } } diff --git a/src/Internal/Assembler/TransferDtoAssembler.php b/src/Internal/Assembler/TransferDtoAssembler.php index 280580f3b..12ca43016 100644 --- a/src/Internal/Assembler/TransferDtoAssembler.php +++ b/src/Internal/Assembler/TransferDtoAssembler.php @@ -6,13 +6,15 @@ use Bavix\Wallet\Internal\Dto\TransferDto; use Bavix\Wallet\Internal\Dto\TransferDtoInterface; +use Bavix\Wallet\Internal\Service\ClockServiceInterface; use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Illuminate\Database\Eloquent\Model; final readonly class TransferDtoAssembler implements TransferDtoAssemblerInterface { public function __construct( - private UuidFactoryServiceInterface $uuidService + private UuidFactoryServiceInterface $uuidService, + private ClockServiceInterface $clockService, ) { } @@ -34,7 +36,9 @@ public function create( $fromModel->getKey(), $toModel->getKey(), $discount, - $fee + $fee, + $this->clockService->now(), + $this->clockService->now(), ); } } diff --git a/src/Internal/Dto/TransactionDto.php b/src/Internal/Dto/TransactionDto.php index f74d5aeec..4261cfe1a 100644 --- a/src/Internal/Dto/TransactionDto.php +++ b/src/Internal/Dto/TransactionDto.php @@ -9,10 +9,6 @@ /** @immutable */ final readonly class TransactionDto implements TransactionDtoInterface { - private DateTimeImmutable $createdAt; - - private DateTimeImmutable $updatedAt; - /** * @param array|null $meta */ @@ -24,10 +20,10 @@ public function __construct( private string $type, private float|int|string $amount, private bool $confirmed, - private ?array $meta + private ?array $meta, + private DateTimeImmutable $createdAt, + private DateTimeImmutable $updatedAt, ) { - $this->createdAt = new DateTimeImmutable(); - $this->updatedAt = new DateTimeImmutable(); } public function getUuid(): string diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index 2f95d88d9..cf604e4d0 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -9,10 +9,6 @@ /** @immutable */ final readonly class TransferDto implements TransferDtoInterface { - private DateTimeImmutable $createdAt; - - private DateTimeImmutable $updatedAt; - public function __construct( private string $uuid, private int $depositId, @@ -21,10 +17,10 @@ public function __construct( private int $fromId, private int $toId, private int $discount, - private string $fee + private string $fee, + private DateTimeImmutable $createdAt, + private DateTimeImmutable $updatedAt, ) { - $this->createdAt = new DateTimeImmutable(); - $this->updatedAt = new DateTimeImmutable(); } public function getUuid(): string From 826eca93caea28f69a0b0b12affb683a5aa40142 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 19:44:48 +0300 Subject: [PATCH 20/21] drop depends --- tests/Infra/PackageModels/TransactionMoney.php | 4 ++-- tests/Infra/Values/Money.php | 14 ++++++++++++++ tests/Units/Domain/WalletExtensionTest.php | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/Infra/Values/Money.php diff --git a/tests/Infra/PackageModels/TransactionMoney.php b/tests/Infra/PackageModels/TransactionMoney.php index 13dcd28ed..b9dfc13b4 100644 --- a/tests/Infra/PackageModels/TransactionMoney.php +++ b/tests/Infra/PackageModels/TransactionMoney.php @@ -4,7 +4,7 @@ namespace Bavix\Wallet\Test\Infra\PackageModels; -use Cknow\Money\Money; +use Bavix\Wallet\Test\Infra\Values\Money; /** * Class Transaction. @@ -17,7 +17,7 @@ final class TransactionMoney extends \Bavix\Wallet\Models\Transaction public function getCurrencyAttribute(): Money { - $this->currency ??= \money($this->amount, $this->meta['currency'] ?? 'USD'); + $this->currency ??= new Money($this->amount, $this->meta['currency'] ?? 'USD'); return $this->currency; } diff --git a/tests/Infra/Values/Money.php b/tests/Infra/Values/Money.php new file mode 100644 index 000000000..be8c160a3 --- /dev/null +++ b/tests/Infra/Values/Money.php @@ -0,0 +1,14 @@ +getKey() > 0); self::assertSame($transaction->amountInt, $buyer->balanceInt); self::assertInstanceOf(TransactionMoney::class, $transaction); - self::assertSame('1000', $transaction->currency->getAmount()); - self::assertSame('EUR', $transaction->currency->getCurrency()->getCode()); + self::assertSame('1000', $transaction->currency->amount); + self::assertSame('EUR', $transaction->currency->currency); } public function testNoCustomAttribute(): void From d2fe9bded9a233167ce13c75def67df334ab6436 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Fri, 5 Jan 2024 19:47:26 +0300 Subject: [PATCH 21/21] remove cknow/laravel-money --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 7aa9b6cde..f0fe678c2 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,6 @@ }, "require-dev": { "brianium/paratest": "^7.3", - "cknow/laravel-money": "^7.2", "ergebnis/phpstan-rules": "^2.1", "infection/infection": "~0.27", "laravel/cashier": "^15.0",