diff --git a/composer.json b/composer.json index bb8449f53..5babcd9be 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "phpstan/phpstan": "^1.7", "phpunit/phpunit": "^9.5", "rector/rector": "^0.13", - "symplify/easy-coding-standard": "^10.2", + "symplify/easy-coding-standard": "^11.0", "vimeo/psalm": "^4.23" }, "suggest": { diff --git a/ecs.php b/ecs.php index 99bcc68eb..fa36535a6 100644 --- a/ecs.php +++ b/ecs.php @@ -44,7 +44,6 @@ $containerConfigurator->import(SetList::SYMPLIFY); $containerConfigurator->import(SetList::COMMON); $containerConfigurator->import(SetList::PSR_12); - $containerConfigurator->import(SetList::PHP_CS_FIXER); $containerConfigurator->import(SetList::CONTROL_STRUCTURES); $containerConfigurator->import(SetList::NAMESPACES); $containerConfigurator->import(SetList::STRICT); diff --git a/src/Commands/TransferFixCommand.php b/src/Commands/TransferFixCommand.php index ca4cf5380..566db2847 100644 --- a/src/Commands/TransferFixCommand.php +++ b/src/Commands/TransferFixCommand.php @@ -12,6 +12,7 @@ final class TransferFixCommand extends Command { protected $signature = 'bx:transfer:fix'; + protected $description = 'Brings transfers to the correct form/to.'; public function handle(Wallet $wallet, Transfer $transfer, CastServiceInterface $castService): void diff --git a/src/External/Dto/Extra.php b/src/External/Dto/Extra.php index 4f2138840..49c2e2ea2 100644 --- a/src/External/Dto/Extra.php +++ b/src/External/Dto/Extra.php @@ -10,6 +10,7 @@ final class Extra implements ExtraDtoInterface { private OptionDtoInterface $deposit; + private OptionDtoInterface $withdraw; public function __construct(OptionDtoInterface|array|null $deposit, OptionDtoInterface|array|null $withdraw) diff --git a/src/Internal/Dto/TransactionDto.php b/src/Internal/Dto/TransactionDto.php index 6ea1d399b..e7a17f947 100644 --- a/src/Internal/Dto/TransactionDto.php +++ b/src/Internal/Dto/TransactionDto.php @@ -10,6 +10,7 @@ final class TransactionDto implements TransactionDtoInterface { private DateTimeImmutable $createdAt; + private DateTimeImmutable $updatedAt; public function __construct( diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index b39a88f14..85016dd2e 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -10,6 +10,7 @@ final class TransferDto implements TransferDtoInterface { private DateTimeImmutable $createdAt; + private DateTimeImmutable $updatedAt; public function __construct( diff --git a/src/Internal/Exceptions/ExceptionInterface.php b/src/Internal/Exceptions/ExceptionInterface.php index 50b956748..f4774fb8b 100644 --- a/src/Internal/Exceptions/ExceptionInterface.php +++ b/src/Internal/Exceptions/ExceptionInterface.php @@ -9,16 +9,28 @@ interface ExceptionInterface extends Throwable { public const AMOUNT_INVALID = 1 << 0; + public const BALANCE_IS_EMPTY = 1 << 1; + public const CONFIRMED_INVALID = 1 << 2; + public const UNCONFIRMED_INVALID = 1 << 3; + public const INSUFFICIENT_FUNDS = 1 << 4; + public const PRODUCT_ENDED = 1 << 5; + public const WALLET_OWNER_INVALID = 1 << 6; + public const CART_EMPTY = 1 << 7; + public const LOCK_PROVIDER_NOT_FOUND = 1 << 8; + public const RECORD_NOT_FOUND = 1 << 9; + public const TRANSACTION_FAILED = 1 << 10; + public const MODEL_NOT_FOUND = 1 << 11; + public const TRANSACTION_START = 1 << 12; } diff --git a/src/Internal/Service/DatabaseService.php b/src/Internal/Service/DatabaseService.php index 3abf75aab..62d2970e8 100644 --- a/src/Internal/Service/DatabaseService.php +++ b/src/Internal/Service/DatabaseService.php @@ -74,7 +74,7 @@ public function transaction(callable $callback): mixed $this->init = false; throw new TransactionFailedException( - 'Transaction failed. Message: '.$throwable->getMessage(), + 'Transaction failed. Message: ' . $throwable->getMessage(), ExceptionInterface::TRANSACTION_FAILED, $throwable ); diff --git a/src/Internal/Service/StorageService.php b/src/Internal/Service/StorageService.php index 3d5e44327..b35abeaf1 100644 --- a/src/Internal/Service/StorageService.php +++ b/src/Internal/Service/StorageService.php @@ -56,7 +56,7 @@ public function sync(string $key, float|int|string $value): bool public function increase(string $key, float|int|string $value): string { return $this->lockService->block( - $key.'::increase', + $key . '::increase', function () use ($key, $value): string { $result = $this->mathService->add($this->get($key), $value); $this->sync($key, $result); diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 84a398aa5..4170149e6 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -32,6 +32,7 @@ class Transaction extends Model { public const TYPE_DEPOSIT = 'deposit'; + public const TYPE_WITHDRAW = 'withdraw'; /** diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index bd87c55c2..471ee9868 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -31,9 +31,13 @@ class Transfer extends Model { public const STATUS_EXCHANGE = 'exchange'; + public const STATUS_TRANSFER = 'transfer'; + public const STATUS_PAID = 'paid'; + public const STATUS_REFUND = 'refund'; + public const STATUS_GIFT = 'gift'; /** diff --git a/src/Objects/Cart.php b/src/Objects/Cart.php index c938ee1ba..d8547e68b 100644 --- a/src/Objects/Cart.php +++ b/src/Objects/Cart.php @@ -139,6 +139,6 @@ public function getBasketDto(): BasketDtoInterface private function productId(ProductInterface $product): string { - return $product::class.':'.$this->castService->getModel($product)->getKey(); + return $product::class . ':' . $this->castService->getModel($product)->getKey(); } } diff --git a/src/Services/AtomicService.php b/src/Services/AtomicService.php index 190bbe738..b2cfc4bbe 100644 --- a/src/Services/AtomicService.php +++ b/src/Services/AtomicService.php @@ -41,6 +41,6 @@ private function key(Wallet $object): string { $wallet = $this->castService->getWallet($object); - return self::PREFIX.'::'.$wallet::class.'::'.$wallet->uuid; + return self::PREFIX . '::' . $wallet::class . '::' . $wallet->uuid; } } diff --git a/src/Services/BookkeeperService.php b/src/Services/BookkeeperService.php index adfe16501..bea9ddfa2 100644 --- a/src/Services/BookkeeperService.php +++ b/src/Services/BookkeeperService.php @@ -63,6 +63,6 @@ public function increase(Wallet $wallet, float|int|string $value): string private function getKey(Wallet $wallet): string { - return __CLASS__.'::'.$wallet->uuid; + return __CLASS__ . '::' . $wallet->uuid; } } diff --git a/src/Services/RegulatorService.php b/src/Services/RegulatorService.php index fb6ad5297..1ed39b0ca 100644 --- a/src/Services/RegulatorService.php +++ b/src/Services/RegulatorService.php @@ -129,6 +129,6 @@ private function persist(Wallet $wallet): void private function getKey(string $uuid): string { - return $this->idempotentKey.'::'.$uuid; + return $this->idempotentKey . '::' . $uuid; } } diff --git a/src/Traits/CartPay.php b/src/Traits/CartPay.php index de9867488..fdda82d97 100644 --- a/src/Traits/CartPay.php +++ b/src/Traits/CartPay.php @@ -128,7 +128,7 @@ public function payCart(CartInterface $cart, bool $force = false): array $assistantService = app(AssistantServiceInterface::class); foreach ($cart->getBasketDto()->items() as $item) { foreach ($item->getItems() as $product) { - $productId = $product::class.':'.$castService->getModel($product)->getKey(); + $productId = $product::class . ':' . $castService->getModel($product)->getKey(); $pricePerItem = $item->getPricePerItem(); if ($pricePerItem === null) { $prices[$productId] ??= $product->getAmountProduct($this); diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index 29d4d0583..b44a062c7 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -109,24 +109,24 @@ final class WalletServiceProvider extends ServiceProvider */ public function boot(): void { - $this->loadTranslationsFrom(dirname(__DIR__).'/resources/lang', 'wallet'); + $this->loadTranslationsFrom(dirname(__DIR__) . '/resources/lang', 'wallet'); if (!$this->app->runningInConsole()) { return; } if ($this->shouldMigrate()) { - $this->loadMigrationsFrom([dirname(__DIR__).'/database']); + $this->loadMigrationsFrom([dirname(__DIR__) . '/database']); } if (function_exists('config_path')) { $this->publishes([ - dirname(__DIR__).'/config/config.php' => config_path('wallet.php'), + dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'), ], 'laravel-wallet-config'); } $this->publishes([ - dirname(__DIR__).'/database/' => database_path('migrations'), + dirname(__DIR__) . '/database/' => database_path('migrations'), ], 'laravel-wallet-migrations'); } @@ -135,7 +135,7 @@ public function boot(): void */ public function register(): void { - $this->mergeConfigFrom(dirname(__DIR__).'/config/config.php', 'wallet'); + $this->mergeConfigFrom(dirname(__DIR__) . '/config/config.php', 'wallet'); $this->commands([TransferFixCommand::class]); $configure = config('wallet', []); diff --git a/tests/Infra/Listeners/WalletCreatedThrowListener.php b/tests/Infra/Listeners/WalletCreatedThrowListener.php index af38e3e25..1e5e1289e 100644 --- a/tests/Infra/Listeners/WalletCreatedThrowListener.php +++ b/tests/Infra/Listeners/WalletCreatedThrowListener.php @@ -18,7 +18,7 @@ public function handle(WalletCreatedEventInterface $walletCreatedEvent): void ->format(DateTimeInterface::ATOM) ; - $message = hash('sha256', $holderType.$uuid.$createdAt); + $message = hash('sha256', $holderType . $uuid . $createdAt); $code = $walletCreatedEvent->getWalletId() + $walletCreatedEvent->getHolderId(); assert($code > 1); diff --git a/tests/Infra/Models/ItemMaxTax.php b/tests/Infra/Models/ItemMaxTax.php index d5129e1a3..888526e91 100644 --- a/tests/Infra/Models/ItemMaxTax.php +++ b/tests/Infra/Models/ItemMaxTax.php @@ -8,17 +8,11 @@ class ItemMaxTax extends Item implements MaximalTaxable { - /** - * {@inheritdoc} - */ public function getTable(): string { return 'items'; } - /** - * {@inheritdoc} - */ public function getFeePercent(): float { return 3; diff --git a/tests/Infra/Models/ItemMinTax.php b/tests/Infra/Models/ItemMinTax.php index 38ac129f9..9fa0fbd1a 100644 --- a/tests/Infra/Models/ItemMinTax.php +++ b/tests/Infra/Models/ItemMinTax.php @@ -8,17 +8,11 @@ class ItemMinTax extends Item implements MinimalTaxable { - /** - * {@inheritdoc} - */ public function getTable(): string { return 'items'; } - /** - * {@inheritdoc} - */ public function getFeePercent(): float { return 3; diff --git a/tests/Infra/PackageModels/Transaction.php b/tests/Infra/PackageModels/Transaction.php index ca122706d..0a2707cc3 100644 --- a/tests/Infra/PackageModels/Transaction.php +++ b/tests/Infra/PackageModels/Transaction.php @@ -11,9 +11,6 @@ */ class Transaction extends \Bavix\Wallet\Models\Transaction { - /** - * {@inheritdoc} - */ public function getFillable(): array { return array_merge($this->fillable, ['bank_method']); diff --git a/tests/Infra/TestServiceProvider.php b/tests/Infra/TestServiceProvider.php index 72e9aa96a..351b03e0b 100644 --- a/tests/Infra/TestServiceProvider.php +++ b/tests/Infra/TestServiceProvider.php @@ -10,6 +10,6 @@ final class TestServiceProvider extends ServiceProvider { public function boot(): void { - $this->loadMigrationsFrom([dirname(__DIR__).'/migrations']); + $this->loadMigrationsFrom([dirname(__DIR__) . '/migrations']); } } diff --git a/tests/Units/Domain/EventTest.php b/tests/Units/Domain/EventTest.php index 9e438555c..c8e62e97c 100644 --- a/tests/Units/Domain/EventTest.php +++ b/tests/Units/Domain/EventTest.php @@ -93,7 +93,7 @@ public function testWalletCreatedThrowListener(): void $uuid = $buyer->wallet->uuid; $createdAt = app(ClockServiceInterface::class)->now()->format(DateTimeInterface::ATOM); - $message = hash('sha256', $holderType.$uuid.$createdAt); + $message = hash('sha256', $holderType . $uuid . $createdAt); // unit $this->expectException(UnknownEventException::class); diff --git a/tests/Units/Domain/MultiWalletTest.php b/tests/Units/Domain/MultiWalletTest.php index 0671a92d4..e4a93ec77 100644 --- a/tests/Units/Domain/MultiWalletTest.php +++ b/tests/Units/Domain/MultiWalletTest.php @@ -587,7 +587,7 @@ public function testMultiWalletTransactionState(): void $wallets = []; foreach (range(1, 10) as $item) { $wallets[] = $user->createWallet([ - 'name' => 'index'.$item, + 'name' => 'index' . $item, ]); } diff --git a/tests/Units/Domain/TransactionsFilterTest.php b/tests/Units/Domain/TransactionsFilterTest.php index e4853e14a..636264ca9 100644 --- a/tests/Units/Domain/TransactionsFilterTest.php +++ b/tests/Units/Domain/TransactionsFilterTest.php @@ -155,8 +155,8 @@ public function testPagination2(): void $query = Transaction::query() ->where(function ($query) use ($buyer, $walletTableName, $transactionTableName) { $query->where('payable_id', '=', $buyer->getKey()) - ->join($walletTableName, $transactionTableName.'.wallet_id', '=', $walletTableName.'.id') - ->select($transactionTableName.'.*', $walletTableName.'.name') + ->join($walletTableName, $transactionTableName . '.wallet_id', '=', $walletTableName . '.id') + ->select($transactionTableName . '.*', $walletTableName . '.name') ->get() ; }) diff --git a/tests/Units/Domain/WalletFloatTest.php b/tests/Units/Domain/WalletFloatTest.php index 3a234c459..2b6357325 100644 --- a/tests/Units/Domain/WalletFloatTest.php +++ b/tests/Units/Domain/WalletFloatTest.php @@ -297,11 +297,11 @@ public function testBitcoin(): void } }); - self::assertSame($user->balance, '256'.str_repeat('0', 32 - 8)); + self::assertSame($user->balance, '256' . str_repeat('0', 32 - 8)); self::assertSame(0, $math->compare($user->balanceFloat, '0.00000256')); - $user->deposit(256 .str_repeat('0', 32)); - $user->depositFloat('0.'.str_repeat('0', 31).'1'); + $user->deposit(256 . str_repeat('0', 32)); + $user->depositFloat('0.' . str_repeat('0', 31) . '1'); [$q, $r] = explode('.', $user->balanceFloat, 2); self::assertSame(strlen($r), $user->wallet->decimal_places);