diff --git a/changelog.md b/changelog.md index 651b41640..d900b8053 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [8.1.0] - 2022-03-13 +### Removed +- Method `getAvailableBalance`. + +### Added +- Methods `withItems`, `withItem`, `withMeta` on Cart-object. + +### Deprecated +- Method `addItems`, `addItem`, `setMeta` on Cart-Object. + ## [8.0.6] - 2022-02-26 ### Updated - Replaced an object with an interface (Events) #444 @ysfkaya @@ -801,7 +811,8 @@ The operation is now executed in the transaction and updates the new `refund` fi - Exceptions: AmountInvalid, BalanceIsEmpty. - Models: Transfer, Transaction. -[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.0.6...develop +[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.1.0...develop +[8.0.6]: https://github.com/bavix/laravel-wallet/compare/8.0.6...8.1.0 [8.0.6]: https://github.com/bavix/laravel-wallet/compare/8.0.5...8.0.6 [8.0.5]: https://github.com/bavix/laravel-wallet/compare/8.0.4...8.0.5 [8.0.4]: https://github.com/bavix/laravel-wallet/compare/8.0.3...8.0.4 diff --git a/config/config.php b/config/config.php index 5b2997497..27aadf324 100644 --- a/config/config.php +++ b/config/config.php @@ -47,14 +47,18 @@ /** * Arbitrary Precision Calculator. * - * 'scale' - length of the mantissa + * 'scale' - length of the mantissa */ - 'math' => ['scale' => 64], + 'math' => [ + 'scale' => 64, + ], /** * Storage of the state of the balance of wallets. */ - 'cache' => ['driver' => 'array'], + 'cache' => [ + 'driver' => 'array', + ], /** * A system for dealing with race conditions. diff --git a/database/2018_11_06_222923_create_transactions_table.php b/database/2018_11_06_222923_create_transactions_table.php index 857e40c48..3bef22cee 100644 --- a/database/2018_11_06_222923_create_transactions_table.php +++ b/database/2018_11_06_222923_create_transactions_table.php @@ -18,8 +18,12 @@ public function up(): void $table->enum('type', ['deposit', 'withdraw'])->index(); $table->decimal('amount', 64, 0); $table->boolean('confirmed'); - $table->json('meta')->nullable(); - $table->uuid('uuid')->unique(); + $table->json('meta') + ->nullable() + ; + $table->uuid('uuid') + ->unique() + ; $table->timestamps(); $table->index(['payable_type', 'payable_id'], 'payable_type_payable_id_ind'); diff --git a/database/2018_11_07_192923_create_transfers_table.php b/database/2018_11_07_192923_create_transfers_table.php index 3536e09cc..e0861bb2c 100644 --- a/database/2018_11_07_192923_create_transfers_table.php +++ b/database/2018_11_07_192923_create_transfers_table.php @@ -17,18 +17,12 @@ public function up(): void $table->morphs('from'); $table->morphs('to'); $table - ->enum( - 'status', - ['exchange', 'transfer', 'paid', 'refund', 'gift'] - ) + ->enum('status', ['exchange', 'transfer', 'paid', 'refund', 'gift']) ->default('transfer') ; $table - ->enum( - 'status_last', - ['exchange', 'transfer', 'paid', 'refund', 'gift'] - ) + ->enum('status_last', ['exchange', 'transfer', 'paid', 'refund', 'gift']) ->nullable() ; @@ -43,7 +37,9 @@ public function up(): void ->default(0) ; - $table->uuid('uuid')->unique(); + $table->uuid('uuid') + ->unique() + ; $table->timestamps(); $table->foreign('deposit_id') diff --git a/database/2018_11_15_124230_create_wallets_table.php b/database/2018_11_15_124230_create_wallets_table.php index 7658ffd24..2799b24f4 100644 --- a/database/2018_11_15_124230_create_wallets_table.php +++ b/database/2018_11_15_124230_create_wallets_table.php @@ -16,12 +16,24 @@ public function up(): void $table->bigIncrements('id'); $table->morphs('holder'); $table->string('name'); - $table->string('slug')->index(); - $table->uuid('uuid')->unique(); - $table->string('description')->nullable(); - $table->json('meta')->nullable(); - $table->decimal('balance', 64, 0)->default(0); - $table->unsignedSmallInteger('decimal_places')->default(2); + $table->string('slug') + ->index() + ; + $table->uuid('uuid') + ->unique() + ; + $table->string('description') + ->nullable() + ; + $table->json('meta') + ->nullable() + ; + $table->decimal('balance', 64, 0) + ->default(0) + ; + $table->unsignedSmallInteger('decimal_places') + ->default(2) + ; $table->timestamps(); $table->unique(['holder_type', 'holder_id', 'slug']); 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 0424fc1ee..5025bd988 100644 --- a/database/2021_11_02_202021_update_wallets_uuid_table.php +++ b/database/2021_11_02_202021_update_wallets_uuid_table.php @@ -34,7 +34,9 @@ public function up(): void }); Schema::table($this->table(), static function (Blueprint $table) { - $table->uuid('uuid')->change(); + $table->uuid('uuid') + ->change() + ; }); } diff --git a/docs/upgrade-guide.md b/docs/upgrade-guide.md index df61a5cd0..1de635716 100644 --- a/docs/upgrade-guide.md +++ b/docs/upgrade-guide.md @@ -194,3 +194,33 @@ On a basket of 150 products, the acceleration is a whopping 24x. All changes can be found in the [pull request](https://github.com/bavix/laravel-wallet/pull/407/files). The kernel has changed globally, I would not recommend switching to version 7.0.0 at the very beginning, there may be bugs. I advise you should at least 7.0.1. + +## 7.x.x → 8.0.x + +Nothing needs to be done. + +## 8.0.x → 8.1.x + +Replace `getAvailableBalance` to `getAvailableBalanceAttribute` (method) or `available_balance` (property). + +--- + +Cart methods now support fluent-dto. It is necessary to replace the old code with a new one, for example: + +```php +// old +$cart = app(\Bavix\Wallet\Objects\Cart::class) + ->addItems($products) + ->addItem($product) + ->setMeta(['hello' => 'world']); + +$cart->addItem($product); + +// new. fluent +$cart = app(\Bavix\Wallet\Objects\Cart::class) + ->withItems($products) + ->withItem($product) + ->withMeta(['hello' => 'world']); + +$cart = $cart->withItem($product); +``` diff --git a/ecs.php b/ecs.php index 1763eaa4c..018afcef5 100644 --- a/ecs.php +++ b/ecs.php @@ -3,10 +3,14 @@ declare(strict_types=1); use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; +use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; +use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; +use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer; use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\EasyCodingStandard\ValueObject\Option; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; @@ -18,6 +22,7 @@ ]]); $services->set(DeclareStrictTypesFixer::class); + $services->set(LineLengthFixer::class); $parameters = $containerConfigurator->parameters(); $parameters->set(Option::PARALLEL, true); @@ -31,10 +36,15 @@ $parameters->set(Option::SKIP, [ PhpdocToCommentFixer::class, + NoUnusedImportsFixer::class, + GeneralPhpdocAnnotationRemoveFixer::class, + NotOperatorWithSuccessorSpaceFixer::class, PhpUnitTestClassRequiresCoversFixer::class, ]); $containerConfigurator->import(SetList::CLEAN_CODE); + $containerConfigurator->import(SetList::SYMPLIFY); + $containerConfigurator->import(SetList::COMMON); $containerConfigurator->import(SetList::PSR_12); $containerConfigurator->import(SetList::PHP_CS_FIXER); $containerConfigurator->import(SetList::CONTROL_STRUCTURES); diff --git a/src/Interfaces/Customer.php b/src/Interfaces/Customer.php index 1f6a59217..3f2813997 100644 --- a/src/Interfaces/Customer.php +++ b/src/Interfaces/Customer.php @@ -115,7 +115,9 @@ public function forceRefundGift(Product $product): bool; */ public function payFreeCart(CartInterface $cart): array; - /** @return Transfer[] */ + /** + * @return Transfer[] + */ public function safePayCart(CartInterface $cart, bool $force = false): array; /** diff --git a/src/Interfaces/Taxable.php b/src/Interfaces/Taxable.php index 5ac65174e..e59fb0ea5 100644 --- a/src/Interfaces/Taxable.php +++ b/src/Interfaces/Taxable.php @@ -7,12 +7,9 @@ interface Taxable { /** - * Specify the percentage of the amount. - * For example, the product costs $100, the equivalent of 15%. - * That's $115. + * Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115. * - * Minimum 0; Maximum 100 - * Example: return 7.5; // 7.5% + * Minimum 0; Maximum 100 Example: return 7.5; // 7.5% * * @return float|int */ diff --git a/src/Interfaces/Wallet.php b/src/Interfaces/Wallet.php index 948b4cc01..09bbd52c6 100644 --- a/src/Interfaces/Wallet.php +++ b/src/Interfaces/Wallet.php @@ -66,7 +66,9 @@ public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = tr */ public function transfer(self $wallet, $amount, ?array $meta = null): Transfer; - /** @param int|string $amount */ + /** + * @param int|string $amount + */ public function safeTransfer(self $wallet, $amount, ?array $meta = null): ?Transfer; /** diff --git a/src/Internal/Assembler/BalanceUpdatedEventAssembler.php b/src/Internal/Assembler/BalanceUpdatedEventAssembler.php index 79dc9ec08..1bb0b0251 100644 --- a/src/Internal/Assembler/BalanceUpdatedEventAssembler.php +++ b/src/Internal/Assembler/BalanceUpdatedEventAssembler.php @@ -11,8 +11,9 @@ final class BalanceUpdatedEventAssembler implements BalanceUpdatedEventAssemblerInterface { - public function __construct(private ClockServiceInterface $clockService) - { + public function __construct( + private ClockServiceInterface $clockService + ) { } public function create(Wallet $wallet): BalanceUpdatedEventInterface diff --git a/src/Internal/Assembler/TransactionDtoAssembler.php b/src/Internal/Assembler/TransactionDtoAssembler.php index eb4c022e8..0dd35eb1b 100644 --- a/src/Internal/Assembler/TransactionDtoAssembler.php +++ b/src/Internal/Assembler/TransactionDtoAssembler.php @@ -11,8 +11,9 @@ final class TransactionDtoAssembler implements TransactionDtoAssemblerInterface { - public function __construct(private UuidFactoryServiceInterface $uuidService) - { + public function __construct( + private UuidFactoryServiceInterface $uuidService + ) { } public function create( diff --git a/src/Internal/Assembler/TransactionQueryAssembler.php b/src/Internal/Assembler/TransactionQueryAssembler.php index df34079c1..d80336ceb 100644 --- a/src/Internal/Assembler/TransactionQueryAssembler.php +++ b/src/Internal/Assembler/TransactionQueryAssembler.php @@ -9,7 +9,9 @@ final class TransactionQueryAssembler implements TransactionQueryAssemblerInterface { - /** @param non-empty-array $uuids */ + /** + * @param non-empty-array $uuids + */ public function create(array $uuids): TransactionQueryInterface { return new TransactionQuery($uuids); diff --git a/src/Internal/Assembler/TransactionQueryAssemblerInterface.php b/src/Internal/Assembler/TransactionQueryAssemblerInterface.php index ec2f8fbdd..70b36f7f3 100644 --- a/src/Internal/Assembler/TransactionQueryAssemblerInterface.php +++ b/src/Internal/Assembler/TransactionQueryAssemblerInterface.php @@ -8,6 +8,8 @@ interface TransactionQueryAssemblerInterface { - /** @param non-empty-array $uuids */ + /** + * @param non-empty-array $uuids + */ public function create(array $uuids): TransactionQueryInterface; } diff --git a/src/Internal/Assembler/TransferDtoAssembler.php b/src/Internal/Assembler/TransferDtoAssembler.php index 427de60ab..bb63f801d 100644 --- a/src/Internal/Assembler/TransferDtoAssembler.php +++ b/src/Internal/Assembler/TransferDtoAssembler.php @@ -11,8 +11,9 @@ final class TransferDtoAssembler implements TransferDtoAssemblerInterface { - public function __construct(private UuidFactoryServiceInterface $uuidService) - { + public function __construct( + private UuidFactoryServiceInterface $uuidService + ) { } public function create( diff --git a/src/Internal/Assembler/TransferLazyDtoAssembler.php b/src/Internal/Assembler/TransferLazyDtoAssembler.php index ac5aa2ed8..796736e75 100644 --- a/src/Internal/Assembler/TransferLazyDtoAssembler.php +++ b/src/Internal/Assembler/TransferLazyDtoAssembler.php @@ -20,14 +20,6 @@ public function create( TransactionDtoInterface $depositDto, string $status ): TransferLazyDtoInterface { - return new TransferLazyDto( - $fromWallet, - $toWallet, - $discount, - $fee, - $withdrawDto, - $depositDto, - $status - ); + return new TransferLazyDto($fromWallet, $toWallet, $discount, $fee, $withdrawDto, $depositDto, $status); } } diff --git a/src/Internal/Assembler/TransferQueryAssembler.php b/src/Internal/Assembler/TransferQueryAssembler.php index 42758cc38..0a1b6f8c5 100644 --- a/src/Internal/Assembler/TransferQueryAssembler.php +++ b/src/Internal/Assembler/TransferQueryAssembler.php @@ -9,7 +9,9 @@ final class TransferQueryAssembler implements TransferQueryAssemblerInterface { - /** @param non-empty-array $uuids */ + /** + * @param non-empty-array $uuids + */ public function create(array $uuids): TransferQueryInterface { return new TransferQuery($uuids); diff --git a/src/Internal/Assembler/TransferQueryAssemblerInterface.php b/src/Internal/Assembler/TransferQueryAssemblerInterface.php index e1da29420..2b5134f92 100644 --- a/src/Internal/Assembler/TransferQueryAssemblerInterface.php +++ b/src/Internal/Assembler/TransferQueryAssemblerInterface.php @@ -8,6 +8,8 @@ interface TransferQueryAssemblerInterface { - /** @param non-empty-array $uuids */ + /** + * @param non-empty-array $uuids + */ public function create(array $uuids): TransferQueryInterface; } diff --git a/src/Internal/Assembler/WalletCreatedEventAssembler.php b/src/Internal/Assembler/WalletCreatedEventAssembler.php index 840e17a3c..8f6761da3 100644 --- a/src/Internal/Assembler/WalletCreatedEventAssembler.php +++ b/src/Internal/Assembler/WalletCreatedEventAssembler.php @@ -11,8 +11,9 @@ final class WalletCreatedEventAssembler implements WalletCreatedEventAssemblerInterface { - public function __construct(private ClockServiceInterface $clockService) - { + public function __construct( + private ClockServiceInterface $clockService + ) { } public function create(Wallet $wallet): WalletCreatedEventInterface diff --git a/src/Internal/Dto/AvailabilityDto.php b/src/Internal/Dto/AvailabilityDto.php index 6e2f3296b..24c52d0b7 100644 --- a/src/Internal/Dto/AvailabilityDto.php +++ b/src/Internal/Dto/AvailabilityDto.php @@ -9,8 +9,11 @@ /** @psalm-immutable */ final class AvailabilityDto implements AvailabilityDtoInterface { - public function __construct(private Customer $customer, private BasketDtoInterface $basketDto, private bool $force) - { + public function __construct( + private Customer $customer, + private BasketDtoInterface $basketDto, + private bool $force + ) { } public function getBasketDto(): BasketDtoInterface diff --git a/src/Internal/Dto/BasketDto.php b/src/Internal/Dto/BasketDto.php index 34f8ebb72..e4381f109 100644 --- a/src/Internal/Dto/BasketDto.php +++ b/src/Internal/Dto/BasketDto.php @@ -9,9 +9,13 @@ final class BasketDto implements BasketDtoInterface { - /** @param non-empty-array $items */ - public function __construct(private array $items, private array $meta) - { + /** + * @param non-empty-array $items + */ + public function __construct( + private array $items, + private array $meta + ) { } public function meta(): array @@ -29,7 +33,9 @@ public function total(): int return iterator_count($this->cursor()); } - /** @return Generator */ + /** + * @return Generator + */ public function cursor(): Generator { foreach ($this->items as $item) { @@ -37,7 +43,9 @@ public function cursor(): Generator } } - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function items(): array { return $this->items; diff --git a/src/Internal/Dto/BasketDtoInterface.php b/src/Internal/Dto/BasketDtoInterface.php index 9764bb4af..8e9f53295 100644 --- a/src/Internal/Dto/BasketDtoInterface.php +++ b/src/Internal/Dto/BasketDtoInterface.php @@ -14,9 +14,13 @@ public function total(): int; public function meta(): array; - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function items(): array; - /** @return Generator */ + /** + * @return Generator + */ public function cursor(): Generator; } diff --git a/src/Internal/Dto/ItemDto.php b/src/Internal/Dto/ItemDto.php index 639d4110f..83b6e8818 100644 --- a/src/Internal/Dto/ItemDto.php +++ b/src/Internal/Dto/ItemDto.php @@ -9,8 +9,10 @@ /** @psalm-immutable */ final class ItemDto implements ItemDtoInterface { - public function __construct(private Product $product, private int $quantity) - { + public function __construct( + private Product $product, + private int $quantity + ) { } /** diff --git a/src/Internal/Dto/ItemDtoInterface.php b/src/Internal/Dto/ItemDtoInterface.php index d9336028e..91d10f421 100644 --- a/src/Internal/Dto/ItemDtoInterface.php +++ b/src/Internal/Dto/ItemDtoInterface.php @@ -9,7 +9,9 @@ interface ItemDtoInterface extends Countable { - /** @return Product[] */ + /** + * @return Product[] + */ public function items(): array; public function count(): int; diff --git a/src/Internal/Dto/TransferLazyDto.php b/src/Internal/Dto/TransferLazyDto.php index 8717bbd4f..ab01a0cf1 100644 --- a/src/Internal/Dto/TransferLazyDto.php +++ b/src/Internal/Dto/TransferLazyDto.php @@ -9,8 +9,15 @@ /** @psalm-immutable */ final class TransferLazyDto implements TransferLazyDtoInterface { - public function __construct(private Wallet $fromWallet, private Wallet $toWallet, private int $discount, private string $fee, private TransactionDtoInterface $withdrawDto, private TransactionDtoInterface $depositDto, private string $status) - { + public function __construct( + private Wallet $fromWallet, + private Wallet $toWallet, + private int $discount, + private string $fee, + private TransactionDtoInterface $withdrawDto, + private TransactionDtoInterface $depositDto, + private string $status + ) { } public function getFromWallet(): Wallet diff --git a/src/Internal/Events/BalanceUpdatedEvent.php b/src/Internal/Events/BalanceUpdatedEvent.php index adfe815ca..7d4e79bc4 100644 --- a/src/Internal/Events/BalanceUpdatedEvent.php +++ b/src/Internal/Events/BalanceUpdatedEvent.php @@ -8,8 +8,12 @@ final class BalanceUpdatedEvent implements BalanceUpdatedEventInterface { - public function __construct(private int $walletId, private string $walletUuid, private string $balance, private DateTimeImmutable $updatedAt) - { + public function __construct( + private int $walletId, + private string $walletUuid, + private string $balance, + private DateTimeImmutable $updatedAt + ) { } public function getWalletId(): int diff --git a/src/Internal/Events/WalletCreatedEvent.php b/src/Internal/Events/WalletCreatedEvent.php index e7cd503ab..ab269e4f1 100644 --- a/src/Internal/Events/WalletCreatedEvent.php +++ b/src/Internal/Events/WalletCreatedEvent.php @@ -8,8 +8,13 @@ final class WalletCreatedEvent implements WalletCreatedEventInterface { - public function __construct(private string $holderType, private int|string $holderId, private string $walletUuid, private int $walletId, private DateTimeImmutable $createdAt) - { + public function __construct( + private string $holderType, + private int|string $holderId, + private string $walletUuid, + private int $walletId, + private DateTimeImmutable $createdAt + ) { } public function getHolderType(): string diff --git a/src/Internal/Query/TransactionQuery.php b/src/Internal/Query/TransactionQuery.php index 10b3be654..7ef80db5f 100644 --- a/src/Internal/Query/TransactionQuery.php +++ b/src/Internal/Query/TransactionQuery.php @@ -7,12 +7,17 @@ /** @psalm-immutable */ final class TransactionQuery implements TransactionQueryInterface { - /** @param non-empty-array $uuids */ - public function __construct(private array $uuids) - { + /** + * @param non-empty-array $uuids + */ + public function __construct( + private array $uuids + ) { } - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function getUuids(): array { return $this->uuids; diff --git a/src/Internal/Query/TransactionQueryInterface.php b/src/Internal/Query/TransactionQueryInterface.php index 627da3ed1..e00cfe3eb 100644 --- a/src/Internal/Query/TransactionQueryInterface.php +++ b/src/Internal/Query/TransactionQueryInterface.php @@ -6,6 +6,8 @@ interface TransactionQueryInterface { - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function getUuids(): array; } diff --git a/src/Internal/Query/TransferQuery.php b/src/Internal/Query/TransferQuery.php index 8146bf423..d0ac040df 100644 --- a/src/Internal/Query/TransferQuery.php +++ b/src/Internal/Query/TransferQuery.php @@ -7,12 +7,17 @@ /** @psalm-immutable */ final class TransferQuery implements TransferQueryInterface { - /** @param non-empty-array $uuids */ - public function __construct(private array $uuids) - { + /** + * @param non-empty-array $uuids + */ + public function __construct( + private array $uuids + ) { } - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function getUuids(): array { return $this->uuids; diff --git a/src/Internal/Query/TransferQueryInterface.php b/src/Internal/Query/TransferQueryInterface.php index 93d01da15..8bef2ac91 100644 --- a/src/Internal/Query/TransferQueryInterface.php +++ b/src/Internal/Query/TransferQueryInterface.php @@ -6,6 +6,8 @@ interface TransferQueryInterface { - /** @return non-empty-array */ + /** + * @return non-empty-array + */ public function getUuids(): array; } diff --git a/src/Internal/Repository/TransactionRepository.php b/src/Internal/Repository/TransactionRepository.php index 57d8fe90b..8e8ec769e 100644 --- a/src/Internal/Repository/TransactionRepository.php +++ b/src/Internal/Repository/TransactionRepository.php @@ -12,8 +12,11 @@ final class TransactionRepository implements TransactionRepositoryInterface { - public function __construct(private TransactionDtoTransformerInterface $transformer, private JsonServiceInterface $jsonService, private Transaction $transaction) - { + public function __construct( + private TransactionDtoTransformerInterface $transformer, + private JsonServiceInterface $jsonService, + private Transaction $transaction + ) { } /** @@ -29,19 +32,23 @@ public function insert(array $objects): void ); } - $this->transaction->newQuery()->insert($values); + $this->transaction->newQuery() + ->insert($values) + ; } public function insertOne(TransactionDtoInterface $dto): Transaction { $attributes = $this->transformer->extract($dto); $instance = $this->transaction->newInstance($attributes); - $instance::withoutEvents(static fn () => $instance->save()); + $instance->saveQuietly(); return $instance; } - /** @return Transaction[] */ + /** + * @return Transaction[] + */ public function findBy(TransactionQueryInterface $query): array { return $this->transaction->newQuery() diff --git a/src/Internal/Repository/TransactionRepositoryInterface.php b/src/Internal/Repository/TransactionRepositoryInterface.php index ec966452f..e3c061a97 100644 --- a/src/Internal/Repository/TransactionRepositoryInterface.php +++ b/src/Internal/Repository/TransactionRepositoryInterface.php @@ -17,6 +17,8 @@ public function insert(array $objects): void; public function insertOne(TransactionDtoInterface $dto): Transaction; - /** @return Transaction[] */ + /** + * @return Transaction[] + */ public function findBy(TransactionQueryInterface $query): array; } diff --git a/src/Internal/Repository/TransferRepository.php b/src/Internal/Repository/TransferRepository.php index d608fb533..5b9fd5cb4 100644 --- a/src/Internal/Repository/TransferRepository.php +++ b/src/Internal/Repository/TransferRepository.php @@ -11,8 +11,10 @@ final class TransferRepository implements TransferRepositoryInterface { - public function __construct(private TransferDtoTransformerInterface $transformer, private Transfer $transfer) - { + public function __construct( + private TransferDtoTransformerInterface $transformer, + private Transfer $transfer + ) { } /** @@ -21,19 +23,23 @@ public function __construct(private TransferDtoTransformerInterface $transformer public function insert(array $objects): void { $values = array_map(fn (TransferDtoInterface $dto): array => $this->transformer->extract($dto), $objects); - $this->transfer->newQuery()->insert($values); + $this->transfer->newQuery() + ->insert($values) + ; } public function insertOne(TransferDtoInterface $dto): Transfer { $attributes = $this->transformer->extract($dto); $instance = $this->transfer->newInstance($attributes); - $instance::withoutEvents(static fn () => $instance->save()); + $instance->saveQuietly(); return $instance; } - /** @return Transfer[] */ + /** + * @return Transfer[] + */ public function findBy(TransferQueryInterface $query): array { return $this->transfer->newQuery() diff --git a/src/Internal/Repository/TransferRepositoryInterface.php b/src/Internal/Repository/TransferRepositoryInterface.php index 0e30bf918..50498b4e8 100644 --- a/src/Internal/Repository/TransferRepositoryInterface.php +++ b/src/Internal/Repository/TransferRepositoryInterface.php @@ -17,6 +17,8 @@ public function insert(array $objects): void; public function insertOne(TransferDtoInterface $dto): Transfer; - /** @return Transfer[] */ + /** + * @return Transfer[] + */ public function findBy(TransferQueryInterface $query): array; } diff --git a/src/Internal/Repository/WalletRepository.php b/src/Internal/Repository/WalletRepository.php index 203f9d0f4..e7a0f0019 100644 --- a/src/Internal/Repository/WalletRepository.php +++ b/src/Internal/Repository/WalletRepository.php @@ -11,14 +11,15 @@ final class WalletRepository implements WalletRepositoryInterface { - public function __construct(private Wallet $wallet) - { + public function __construct( + private Wallet $wallet + ) { } public function create(array $attributes): Wallet { $instance = $this->wallet->newInstance($attributes); - $instance::withoutEvents(static fn () => $instance->save()); + $instance->saveQuietly(); return $instance; } @@ -50,19 +51,29 @@ public function findBySlug(string $holderType, int|string $holderId, string $slu } } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getById(int $id): Wallet { - return $this->getBy(['id' => $id]); + return $this->getBy([ + 'id' => $id, + ]); } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getByUuid(string $uuid): Wallet { - return $this->getBy(['uuid' => $uuid]); + return $this->getBy([ + 'uuid' => $uuid, + ]); } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getBySlug(string $holderType, int|string $holderId, string $slug): Wallet { return $this->getBy([ @@ -72,11 +83,16 @@ public function getBySlug(string $holderType, int|string $holderId, string $slug ]); } - /** @param array $attributes */ + /** + * @param array $attributes + */ private function getBy(array $attributes): Wallet { try { - $wallet = $this->wallet->newQuery()->where($attributes)->firstOrFail(); + $wallet = $this->wallet->newQuery() + ->where($attributes) + ->firstOrFail() + ; assert($wallet instanceof Wallet); return $wallet; diff --git a/src/Internal/Repository/WalletRepositoryInterface.php b/src/Internal/Repository/WalletRepositoryInterface.php index 001bdf5df..6785e3e9d 100644 --- a/src/Internal/Repository/WalletRepositoryInterface.php +++ b/src/Internal/Repository/WalletRepositoryInterface.php @@ -17,12 +17,18 @@ public function findByUuid(string $uuid): ?Wallet; public function findBySlug(string $holderType, int|string $holderId, string $slug): ?Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getById(int $id): Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getByUuid(string $uuid): Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getBySlug(string $holderType, int|string $holderId, string $slug): Wallet; } diff --git a/src/Internal/Service/DatabaseService.php b/src/Internal/Service/DatabaseService.php index da715d100..1d61f6071 100644 --- a/src/Internal/Service/DatabaseService.php +++ b/src/Internal/Service/DatabaseService.php @@ -22,9 +22,7 @@ public function __construct( private RegulatorServiceInterface $regulatorService, ConfigRepository $config ) { - $this->connection = $connectionResolver->connection( - $config->get('wallet.database.connection') - ); + $this->connection = $connectionResolver->connection($config->get('wallet.database.connection')); } /** diff --git a/src/Internal/Service/DispatcherService.php b/src/Internal/Service/DispatcherService.php index 64c6dd0bf..201d4e93a 100644 --- a/src/Internal/Service/DispatcherService.php +++ b/src/Internal/Service/DispatcherService.php @@ -13,11 +13,14 @@ final class DispatcherService implements DispatcherServiceInterface { - /** @var string[] */ + /** + * @var string[] + */ private array $events = []; - public function __construct(private Dispatcher $dispatcher) - { + public function __construct( + private Dispatcher $dispatcher + ) { } public function dispatch(EventInterface $event): void @@ -41,7 +44,9 @@ public function forgot(): void } } - /** @throws UnknownEventException */ + /** + * @throws UnknownEventException + */ private function getEventName(EventInterface $event): string { if ($event instanceof BalanceUpdatedEventInterface) { @@ -52,9 +57,6 @@ private function getEventName(EventInterface $event): string return WalletCreatedEventInterface::class; } - throw new UnknownEventException( - 'Unknown event '.$event::class, - ExceptionInterface::UNKNOWN_EVENT - ); + throw new UnknownEventException('Unknown event '.$event::class, ExceptionInterface::UNKNOWN_EVENT); } } diff --git a/src/Internal/Service/LockService.php b/src/Internal/Service/LockService.php index adacaceb9..5e7d5f62a 100644 --- a/src/Internal/Service/LockService.php +++ b/src/Internal/Service/LockService.php @@ -17,20 +17,19 @@ final class LockService implements LockServiceInterface private int $seconds; - public function __construct( - CacheManager $cacheManager, - ConfigRepository $config - ) { + public function __construct(CacheManager $cacheManager, ConfigRepository $config) + { $this->seconds = (int) $config->get('wallet.lock.seconds', 1); - $this->cache = $cacheManager->driver( - $config->get('wallet.lock.driver', 'array') - ); + $this->cache = $cacheManager->driver($config->get('wallet.lock.driver', 'array')); } - /** @throws LockProviderNotFoundException */ + /** + * @throws LockProviderNotFoundException + */ public function block(string $key, callable $callback) { - return $this->getLockProvider()->lock($key) + return $this->getLockProvider() + ->lock($key) ->block($this->seconds, $callback) ; } diff --git a/src/Internal/Service/MathServiceInterface.php b/src/Internal/Service/MathServiceInterface.php index d41e48cea..41e84e27b 100644 --- a/src/Internal/Service/MathServiceInterface.php +++ b/src/Internal/Service/MathServiceInterface.php @@ -36,7 +36,9 @@ public function mul($first, $second, ?int $scale = null): string; */ public function pow($first, $second, ?int $scale = null): string; - /** @param float|int|string $number */ + /** + * @param float|int|string $number + */ public function powTen($number): string; /** diff --git a/src/Internal/Service/StorageService.php b/src/Internal/Service/StorageService.php index d88ab6e27..f7ff8c58d 100644 --- a/src/Internal/Service/StorageService.php +++ b/src/Internal/Service/StorageService.php @@ -11,8 +11,11 @@ final class StorageService implements StorageServiceInterface { - public function __construct(private LockServiceInterface $lockService, private MathServiceInterface $mathService, private CacheRepository $cacheRepository) - { + public function __construct( + private LockServiceInterface $lockService, + private MathServiceInterface $mathService, + private CacheRepository $cacheRepository + ) { } public function flush(): bool @@ -25,7 +28,9 @@ public function missing(string $key): bool return $this->cacheRepository->forget($key); } - /** @throws RecordNotFoundException */ + /** + * @throws RecordNotFoundException + */ public function get(string $key): string { $value = $this->cacheRepository->get($key); @@ -39,7 +44,9 @@ public function get(string $key): string return $this->mathService->round($value); } - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function sync(string $key, $value): bool { return $this->cacheRepository->set($key, $value); diff --git a/src/Internal/Service/StorageServiceInterface.php b/src/Internal/Service/StorageServiceInterface.php index 1ada039b0..bf2eba6ac 100644 --- a/src/Internal/Service/StorageServiceInterface.php +++ b/src/Internal/Service/StorageServiceInterface.php @@ -13,10 +13,14 @@ public function flush(): bool; public function missing(string $key): bool; - /** @throws RecordNotFoundException */ + /** + * @throws RecordNotFoundException + */ public function get(string $key): string; - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function sync(string $key, $value): bool; /** diff --git a/src/Internal/Service/TranslatorService.php b/src/Internal/Service/TranslatorService.php index 9f7c7ec8b..62fa2a20f 100644 --- a/src/Internal/Service/TranslatorService.php +++ b/src/Internal/Service/TranslatorService.php @@ -8,8 +8,9 @@ final class TranslatorService implements TranslatorServiceInterface { - public function __construct(private Translator $translator) - { + public function __construct( + private Translator $translator + ) { } public function get(string $key): string diff --git a/src/Internal/Service/UuidFactoryService.php b/src/Internal/Service/UuidFactoryService.php index 3a83756bc..965fcd28c 100644 --- a/src/Internal/Service/UuidFactoryService.php +++ b/src/Internal/Service/UuidFactoryService.php @@ -8,12 +8,15 @@ final class UuidFactoryService implements UuidFactoryServiceInterface { - public function __construct(private UuidFactory $uuidFactory) - { + public function __construct( + private UuidFactory $uuidFactory + ) { } public function uuid4(): string { - return $this->uuidFactory->uuid4()->toString(); + return $this->uuidFactory->uuid4() + ->toString() + ; } } diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 1f121fa15..5f4163433 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -91,8 +91,7 @@ public function setNameAttribute(string $name): void $this->attributes['name'] = $name; /** - * Must be updated only if the model does not exist - * or the slug is empty. + * Must be updated only if the model does not exist or the slug is empty. */ if (!$this->exists && !array_key_exists('slug', $this->attributes)) { $this->attributes['slug'] = Str::slug($name); @@ -100,8 +99,7 @@ public function setNameAttribute(string $name): void } /** - * Under ideal conditions, you will never need a method. - * Needed to deal with out-of-sync. + * Under ideal conditions, you will never need a method. Needed to deal with out-of-sync. * * @throws LockProviderNotFoundException * @throws RecordsNotFoundException @@ -121,18 +119,13 @@ public function refreshBalance(): bool }); } - /** @codeCoverageIgnore */ public function getOriginalBalanceAttribute(): string { - if (method_exists($this, 'getRawOriginal')) { - return (string) $this->getRawOriginal('balance', 0); - } - - return (string) $this->getOriginal('balance', 0); + return (string) $this->getRawOriginal('balance', 0); } /** - * @return float|int + * @return float|int|string */ public function getAvailableBalanceAttribute() { @@ -142,18 +135,6 @@ public function getAvailableBalanceAttribute() ; } - /** - * @deprecated - * @see getAvailableBalanceAttribute - * @codeCoverageIgnore - * - * @return float|int - */ - public function getAvailableBalance() - { - return $this->getAvailableBalanceAttribute(); - } - public function holder(): MorphTo { return $this->morphTo(); diff --git a/src/Objects/Cart.php b/src/Objects/Cart.php index 2ef2f2ba1..eb3156fe1 100644 --- a/src/Objects/Cart.php +++ b/src/Objects/Cart.php @@ -26,13 +26,17 @@ final class Cart implements Countable, CartInterface */ private array $items = []; - /** @var array */ + /** + * @var array + */ private array $quantity = []; private array $meta = []; - public function __construct(private CastServiceInterface $castService, private MathServiceInterface $math) - { + public function __construct( + private CastServiceInterface $castService, + private MathServiceInterface $math + ) { } public function getMeta(): array @@ -40,6 +44,20 @@ public function getMeta(): array return $this->meta; } + public function withMeta(array $meta): self + { + $self = clone $this; + $self->meta = $meta; + + return $self; + } + + /** + * @codeCoverageIgnore + * + * @deprecated + * @see withMeta + */ public function setMeta(array $meta): self { $this->meta = $meta; @@ -47,6 +65,17 @@ public function setMeta(array $meta): self return $this; } + public function withItem(Product $product, int $quantity = 1): self + { + return (clone $this)->addItem($product, $quantity); + } + + /** + * @codeCoverageIgnore + * + * @deprecated + * @see withItem + */ public function addItem(Product $product, int $quantity = 1): self { $this->addQuantity($product, $quantity); @@ -56,6 +85,22 @@ public function addItem(Product $product, int $quantity = 1): self return $this; } + public function withItems(iterable $products): self + { + $self = clone $this; + foreach ($products as $product) { + $self = $self->withItem($product); + } + + return $self; + } + + /** + * @codeCoverageIgnore + * + * @deprecated + * @see withItems + */ public function addItems(iterable $products): self { foreach ($products as $product) { @@ -114,10 +159,7 @@ public function getBasketDto(): BasketDtoInterface ); if (count($items) === 0) { - throw new CartEmptyException( - 'Cart is empty', - ExceptionInterface::CART_EMPTY - ); + throw new CartEmptyException('Cart is empty', ExceptionInterface::CART_EMPTY); } return new BasketDto($items, $this->getMeta()); diff --git a/src/Services/AssistantService.php b/src/Services/AssistantService.php index 54664c7c4..1a6c7fce1 100644 --- a/src/Services/AssistantService.php +++ b/src/Services/AssistantService.php @@ -10,8 +10,9 @@ final class AssistantService implements AssistantServiceInterface { - public function __construct(private MathServiceInterface $mathService) - { + public function __construct( + private MathServiceInterface $mathService + ) { } /** @@ -41,9 +42,6 @@ public function getSums(array $transactions): array } } - return array_filter( - $amounts, - fn (string $amount): bool => $this->mathService->compare($amount, 0) !== 0 - ); + return array_filter($amounts, fn (string $amount): bool => $this->mathService->compare($amount, 0) !== 0); } } diff --git a/src/Services/AtmService.php b/src/Services/AtmService.php index 3fa7577be..0ac56424a 100644 --- a/src/Services/AtmService.php +++ b/src/Services/AtmService.php @@ -16,8 +16,13 @@ /** @psalm-internal */ final class AtmService implements AtmServiceInterface { - public function __construct(private TransactionQueryAssemblerInterface $transactionQueryAssembler, private TransferQueryAssemblerInterface $transferQueryAssembler, private TransactionRepositoryInterface $transactionRepository, private TransferRepositoryInterface $transferRepository, private AssistantServiceInterface $assistantService) - { + public function __construct( + 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 518cdf36a..154f20a15 100644 --- a/src/Services/AtomicService.php +++ b/src/Services/AtomicService.php @@ -16,8 +16,11 @@ final class AtomicService implements AtomicServiceInterface { private const PREFIX = 'wallet_atomic::'; - public function __construct(private DatabaseServiceInterface $databaseService, private LockServiceInterface $lockService, private CastServiceInterface $castService) - { + public function __construct( + private DatabaseServiceInterface $databaseService, + private LockServiceInterface $lockService, + private CastServiceInterface $castService + ) { } /** diff --git a/src/Services/BookkeeperService.php b/src/Services/BookkeeperService.php index c1019fc0f..98c8b6600 100644 --- a/src/Services/BookkeeperService.php +++ b/src/Services/BookkeeperService.php @@ -12,8 +12,10 @@ final class BookkeeperService implements BookkeeperServiceInterface { - public function __construct(private StorageServiceInterface $storageService, private LockServiceInterface $lockService) - { + public function __construct( + private StorageServiceInterface $storageService, + private LockServiceInterface $lockService + ) { } public function missing(Wallet $wallet): bool diff --git a/src/Services/CastService.php b/src/Services/CastService.php index 5b5e6c107..6b89be34d 100644 --- a/src/Services/CastService.php +++ b/src/Services/CastService.php @@ -15,11 +15,16 @@ /** @psalm-internal */ final class CastService implements CastServiceInterface { - public function __construct(private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, private DispatcherServiceInterface $dispatcherService, private DatabaseServiceInterface $databaseService) - { + public function __construct( + private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, + private DispatcherServiceInterface $dispatcherService, + private DatabaseServiceInterface $databaseService + ) { } - /** @throws ExceptionInterface */ + /** + * @throws ExceptionInterface + */ public function getWallet(Wallet $object, bool $save = true): WalletModel { $wallet = $this->getModel($object); @@ -30,7 +35,7 @@ public function getWallet(Wallet $object, bool $save = true): WalletModel if ($save && !$wallet->exists) { $this->databaseService->transaction(function () use ($wallet) { - $result = $wallet::withoutEvents(fn () => $wallet->save()); + $result = $wallet->saveQuietly(); $this->dispatcherService->dispatch($this->walletCreatedEventAssembler->create($wallet)); return $result; @@ -40,7 +45,9 @@ public function getWallet(Wallet $object, bool $save = true): WalletModel return $wallet; } - /** @param Model|Wallet $object */ + /** + * @param Model|Wallet $object + */ public function getHolder($object): Model { return $this->getModel($object instanceof WalletModel ? $object->holder : $object); diff --git a/src/Services/CastServiceInterface.php b/src/Services/CastServiceInterface.php index b826c58ae..56487b3b7 100644 --- a/src/Services/CastServiceInterface.php +++ b/src/Services/CastServiceInterface.php @@ -12,7 +12,9 @@ interface CastServiceInterface { public function getWallet(Wallet $object, bool $save = true): WalletModel; - /** @param Model|Wallet $object */ + /** + * @param Model|Wallet $object + */ public function getHolder($object): Model; public function getModel(object $object): Model; diff --git a/src/Services/CommonServiceLegacy.php b/src/Services/CommonServiceLegacy.php index 989afff3e..3bbe53389 100644 --- a/src/Services/CommonServiceLegacy.php +++ b/src/Services/CommonServiceLegacy.php @@ -20,8 +20,15 @@ /** @deprecated */ final class CommonServiceLegacy { - public function __construct(private CastServiceInterface $castService, private AssistantServiceInterface $assistantService, private DatabaseServiceInterface $databaseService, private PrepareServiceInterface $prepareService, private TransferDtoAssemblerInterface $transferDtoAssembler, private RegulatorServiceInterface $regulatorService, private AtmServiceInterface $atmService) - { + public function __construct( + private CastServiceInterface $castService, + private AssistantServiceInterface $assistantService, + private DatabaseServiceInterface $databaseService, + private PrepareServiceInterface $prepareService, + private TransferDtoAssemblerInterface $transferDtoAssembler, + private RegulatorServiceInterface $regulatorService, + private AtmServiceInterface $atmService + ) { } /** @@ -33,8 +40,13 @@ public function __construct(private CastServiceInterface $castService, private A * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceTransfer(Wallet $from, Wallet $to, $amount, ?array $meta = null, string $status = Transfer::STATUS_TRANSFER): Transfer - { + public function forceTransfer( + Wallet $from, + Wallet $to, + $amount, + ?array $meta = null, + string $status = Transfer::STATUS_TRANSFER + ): Transfer { $transferLazyDto = $this->prepareService->transferLazy($from, $to, $status, $amount, $meta); $transfers = $this->applyTransfers([$transferLazyDto]); @@ -99,8 +111,13 @@ public function applyTransfers(array $objects): array * @throws LockProviderNotFoundException * @throws RecordNotFoundException */ - public function makeTransaction(Wallet $wallet, string $type, $amount, ?array $meta, bool $confirmed = true): Transaction - { + public function makeTransaction( + Wallet $wallet, + string $type, + $amount, + ?array $meta, + bool $confirmed = true + ): Transaction { assert(in_array($type, [Transaction::TYPE_DEPOSIT, Transaction::TYPE_WITHDRAW], true)); if ($type === Transaction::TYPE_DEPOSIT) { @@ -109,10 +126,9 @@ public function makeTransaction(Wallet $wallet, string $type, $amount, ?array $m $dto = $this->prepareService->withdraw($wallet, (string) $amount, $meta, $confirmed); } - $transactions = $this->applyTransactions( - [$dto->getWalletId() => $wallet], - [$dto], - ); + $transactions = $this->applyTransactions([ + $dto->getWalletId() => $wallet, + ], [$dto],); return current($transactions); } diff --git a/src/Services/ConsistencyService.php b/src/Services/ConsistencyService.php index 7cee4c13b..23780b2f2 100644 --- a/src/Services/ConsistencyService.php +++ b/src/Services/ConsistencyService.php @@ -15,8 +15,11 @@ final class ConsistencyService implements ConsistencyServiceInterface { - public function __construct(private TranslatorServiceInterface $translatorService, private MathServiceInterface $mathService, private CastServiceInterface $castService) - { + public function __construct( + private TranslatorServiceInterface $translatorService, + private MathServiceInterface $mathService, + private CastServiceInterface $castService + ) { } /** diff --git a/src/Services/ExchangeService.php b/src/Services/ExchangeService.php index 5c0e294dc..0c047b758 100644 --- a/src/Services/ExchangeService.php +++ b/src/Services/ExchangeService.php @@ -6,7 +6,9 @@ final class ExchangeService implements ExchangeServiceInterface { - /** @param float|int|string $amount */ + /** + * @param float|int|string $amount + */ public function convertTo(string $fromCurrency, string $toCurrency, $amount): string { return (string) $amount; diff --git a/src/Services/ExchangeServiceInterface.php b/src/Services/ExchangeServiceInterface.php index a53dee7c4..8f846f369 100644 --- a/src/Services/ExchangeServiceInterface.php +++ b/src/Services/ExchangeServiceInterface.php @@ -6,6 +6,8 @@ interface ExchangeServiceInterface { - /** @param float|int|string $amount */ + /** + * @param float|int|string $amount + */ public function convertTo(string $fromCurrency, string $toCurrency, $amount): string; } diff --git a/src/Services/MetaServiceLegacy.php b/src/Services/MetaServiceLegacy.php index d21fbe1b9..78c1b362c 100644 --- a/src/Services/MetaServiceLegacy.php +++ b/src/Services/MetaServiceLegacy.php @@ -12,7 +12,9 @@ final class MetaServiceLegacy { public function getMeta(CartInterface $cart, Product $product): ?array { - $metaCart = $cart->getBasketDto()->meta(); + $metaCart = $cart->getBasketDto() + ->meta() + ; $metaProduct = $product->getMetaProduct(); if ($metaProduct !== null) { diff --git a/src/Services/PrepareService.php b/src/Services/PrepareService.php index 452d466a4..dccaa836d 100644 --- a/src/Services/PrepareService.php +++ b/src/Services/PrepareService.php @@ -15,20 +15,32 @@ final class PrepareService implements PrepareServiceInterface { - public function __construct(private TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler, private TransactionDtoAssemblerInterface $transactionDtoAssembler, private DiscountServiceInterface $personalDiscountService, private ConsistencyServiceInterface $consistencyService, private CastServiceInterface $castService, private MathServiceInterface $mathService, private TaxServiceInterface $taxService) - { + public function __construct( + private TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler, + private TransactionDtoAssemblerInterface $transactionDtoAssembler, + private DiscountServiceInterface $personalDiscountService, + private ConsistencyServiceInterface $consistencyService, + private CastServiceInterface $castService, + private MathServiceInterface $mathService, + private TaxServiceInterface $taxService + ) { } /** * @throws AmountInvalid */ - public function deposit(Wallet $wallet, string $amount, ?array $meta, bool $confirmed = true): TransactionDtoInterface - { + public function deposit( + Wallet $wallet, + string $amount, + ?array $meta, + bool $confirmed = true + ): TransactionDtoInterface { $this->consistencyService->checkPositive($amount); return $this->transactionDtoAssembler->create( $this->castService->getHolder($wallet), - $this->castService->getWallet($wallet)->getKey(), + $this->castService->getWallet($wallet) + ->getKey(), Transaction::TYPE_DEPOSIT, $amount, $confirmed, @@ -39,13 +51,18 @@ public function deposit(Wallet $wallet, string $amount, ?array $meta, bool $conf /** * @throws AmountInvalid */ - public function withdraw(Wallet $wallet, string $amount, ?array $meta, bool $confirmed = true): TransactionDtoInterface - { + public function withdraw( + Wallet $wallet, + string $amount, + ?array $meta, + bool $confirmed = true + ): TransactionDtoInterface { $this->consistencyService->checkPositive($amount); return $this->transactionDtoAssembler->create( $this->castService->getHolder($wallet), - $this->castService->getWallet($wallet)->getKey(), + $this->castService->getWallet($wallet) + ->getKey(), Transaction::TYPE_WITHDRAW, $this->mathService->negative($amount), $confirmed, @@ -58,8 +75,13 @@ public function withdraw(Wallet $wallet, string $amount, ?array $meta, bool $con * * @throws AmountInvalid */ - public function transferLazy(Wallet $from, Wallet $to, string $status, $amount, ?array $meta = null): TransferLazyDtoInterface - { + public function transferLazy( + Wallet $from, + Wallet $to, + string $status, + $amount, + ?array $meta = null + ): TransferLazyDtoInterface { $discount = $this->personalDiscountService->getDiscount($from, $to); $from = $this->castService->getWallet($from); $fee = $this->taxService->getFee($to, $amount); diff --git a/src/Services/PrepareServiceInterface.php b/src/Services/PrepareServiceInterface.php index a579ef3ef..7eb2d0291 100644 --- a/src/Services/PrepareServiceInterface.php +++ b/src/Services/PrepareServiceInterface.php @@ -14,17 +14,33 @@ interface PrepareServiceInterface /** * @throws AmountInvalid */ - public function deposit(Wallet $wallet, string $amount, ?array $meta, bool $confirmed = true): TransactionDtoInterface; + public function deposit( + Wallet $wallet, + string $amount, + ?array $meta, + bool $confirmed = true + ): TransactionDtoInterface; /** * @throws AmountInvalid */ - public function withdraw(Wallet $wallet, string $amount, ?array $meta, bool $confirmed = true): TransactionDtoInterface; + public function withdraw( + Wallet $wallet, + string $amount, + ?array $meta, + bool $confirmed = true + ): TransactionDtoInterface; /** * @param float|int|string $amount * * @throws AmountInvalid */ - public function transferLazy(Wallet $from, Wallet $to, string $status, $amount, ?array $meta = null): TransferLazyDtoInterface; + public function transferLazy( + Wallet $from, + Wallet $to, + string $status, + $amount, + ?array $meta = null + ): TransferLazyDtoInterface; } diff --git a/src/Services/PurchaseServiceInterface.php b/src/Services/PurchaseServiceInterface.php index 873e93380..562534ec6 100644 --- a/src/Services/PurchaseServiceInterface.php +++ b/src/Services/PurchaseServiceInterface.php @@ -10,6 +10,8 @@ interface PurchaseServiceInterface { - /** @return Transfer[] */ + /** + * @return Transfer[] + */ public function already(Customer $customer, BasketDtoInterface $basketDto, bool $gifts = false): array; } diff --git a/src/Services/RegulatorService.php b/src/Services/RegulatorService.php index 04ed4a31b..d17cc5733 100644 --- a/src/Services/RegulatorService.php +++ b/src/Services/RegulatorService.php @@ -16,7 +16,9 @@ final class RegulatorService implements RegulatorServiceInterface { private string $idempotentKey; - /** @var Wallet[] */ + /** + * @var Wallet[] + */ private array $wallets = []; public function __construct( @@ -53,7 +55,9 @@ public function amount(Wallet $wallet): string ); } - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function sync(Wallet $wallet, $value): bool { $this->persist($wallet); @@ -66,7 +70,9 @@ public function sync(Wallet $wallet, $value): bool ); } - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function increase(Wallet $wallet, $value): string { $this->persist($wallet); @@ -81,7 +87,9 @@ public function increase(Wallet $wallet, $value): string return $this->amount($wallet); } - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function decrease(Wallet $wallet, $value): string { return $this->increase($wallet, $this->mathService->negative($value)); @@ -96,8 +104,15 @@ public function approve(): void } $balance = $this->bookkeeperService->increase($wallet, $diffValue); - $wallet->newQuery()->whereKey($wallet->getKey())->update(['balance' => $balance]); // ?qN - $wallet->fill(['balance' => $balance])->syncOriginalAttribute('balance'); + $wallet->newQuery() + ->whereKey($wallet->getKey()) + ->update([ + 'balance' => $balance, + ]) // ?qN + ; + $wallet->fill([ + 'balance' => $balance, + ])->syncOriginalAttribute('balance'); $event = $this->balanceUpdatedEventAssembler->create($wallet); $this->dispatcherService->dispatch($event); diff --git a/src/Services/RegulatorServiceInterface.php b/src/Services/RegulatorServiceInterface.php index 956ec2b7c..b60963750 100644 --- a/src/Services/RegulatorServiceInterface.php +++ b/src/Services/RegulatorServiceInterface.php @@ -14,13 +14,19 @@ public function diff(Wallet $wallet): string; public function amount(Wallet $wallet): string; - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function sync(Wallet $wallet, $value): bool; - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function increase(Wallet $wallet, $value): string; - /** @param float|int|string $value */ + /** + * @param float|int|string $value + */ public function decrease(Wallet $wallet, $value): string; public function approve(): void; diff --git a/src/Services/TaxService.php b/src/Services/TaxService.php index 51d6a59ae..6fc5d2c7e 100644 --- a/src/Services/TaxService.php +++ b/src/Services/TaxService.php @@ -11,8 +11,10 @@ final class TaxService implements TaxServiceInterface { - public function __construct(private MathServiceInterface $mathService, private CastServiceInterface $castService) - { + public function __construct( + private MathServiceInterface $mathService, + private CastServiceInterface $castService + ) { } /** @@ -26,7 +28,8 @@ public function getFee(Wallet $wallet, $amount): string $this->mathService->div( $this->mathService->mul($amount, $wallet->getFeePercent(), 0), 100, - $this->castService->getWallet($wallet)->decimal_places + $this->castService->getWallet($wallet) + ->decimal_places ) ); } diff --git a/src/Services/WalletService.php b/src/Services/WalletService.php index 58ffb4b4b..ec6d234e1 100644 --- a/src/Services/WalletService.php +++ b/src/Services/WalletService.php @@ -14,8 +14,12 @@ final class WalletService implements WalletServiceInterface { - public function __construct(private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, private UuidFactoryServiceInterface $uuidFactoryService, private DispatcherServiceInterface $dispatcherService, private WalletRepositoryInterface $walletRepository) - { + public function __construct( + private WalletCreatedEventAssemblerInterface $walletCreatedEventAssembler, + private UuidFactoryServiceInterface $uuidFactoryService, + private DispatcherServiceInterface $dispatcherService, + private WalletRepositoryInterface $walletRepository + ) { } public function create(Model $model, array $data): Wallet @@ -38,11 +42,7 @@ public function create(Model $model, array $data): Wallet public function findBySlug(Model $model, string $slug): ?Wallet { - return $this->walletRepository->findBySlug( - $model->getMorphClass(), - $model->getKey(), - $slug - ); + return $this->walletRepository->findBySlug($model->getMorphClass(), $model->getKey(), $slug); } public function findByUuid(string $uuid): ?Wallet @@ -55,23 +55,25 @@ public function findById(int $id): ?Wallet return $this->walletRepository->findById($id); } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getBySlug(Model $model, string $slug): Wallet { - return $this->walletRepository->getBySlug( - $model->getMorphClass(), - $model->getKey(), - $slug - ); + return $this->walletRepository->getBySlug($model->getMorphClass(), $model->getKey(), $slug); } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getByUuid(string $uuid): Wallet { return $this->walletRepository->getByUuid($uuid); } - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getById(int $id): Wallet { return $this->walletRepository->getById($id); diff --git a/src/Services/WalletServiceInterface.php b/src/Services/WalletServiceInterface.php index 454c60162..7e24163be 100644 --- a/src/Services/WalletServiceInterface.php +++ b/src/Services/WalletServiceInterface.php @@ -18,12 +18,18 @@ public function findByUuid(string $uuid): ?Wallet; public function findById(int $id): ?Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getBySlug(Model $model, string $slug): Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getByUuid(string $uuid): Wallet; - /** @throws ModelNotFoundException */ + /** + * @throws ModelNotFoundException + */ public function getById(int $id): Wallet; } diff --git a/src/Traits/CanConfirm.php b/src/Traits/CanConfirm.php index 5c537565f..4493325f8 100644 --- a/src/Traits/CanConfirm.php +++ b/src/Traits/CanConfirm.php @@ -90,7 +90,9 @@ public function resetConfirm(Transaction $transaction): bool app(RegulatorServiceInterface::class)->decrease($wallet, $transaction->amount); - return $transaction->update(['confirmed' => false]); + return $transaction->update([ + 'confirmed' => false, + ]); }); } @@ -132,7 +134,9 @@ public function forceConfirm(Transaction $transaction): bool app(RegulatorServiceInterface::class)->increase($wallet, $transaction->amount); - return $transaction->update(['confirmed' => true]); + return $transaction->update([ + 'confirmed' => true, + ]); }); } } diff --git a/src/Traits/CanExchange.php b/src/Traits/CanExchange.php index eb26af7ec..89e3cc0ef 100644 --- a/src/Traits/CanExchange.php +++ b/src/Traits/CanExchange.php @@ -78,13 +78,19 @@ public function forceExchange(Wallet $to, $amount, ?array $meta = null): Transfe $taxService = app(TaxServiceInterface::class); $fee = $taxService->getFee($to, $amount); $rate = app(ExchangeServiceInterface::class)->convertTo( - $castService->getWallet($this)->currency, - $castService->getWallet($to)->currency, + $castService->getWallet($this) + ->currency, + $castService->getWallet($to) + ->currency, 1 ); $withdrawDto = $prepareService->withdraw($this, $mathService->add($amount, $fee), $meta); - $depositDto = $prepareService->deposit($to, $mathService->floor($mathService->mul($amount, $rate, 1)), $meta); + $depositDto = $prepareService->deposit( + $to, + $mathService->floor($mathService->mul($amount, $rate, 1)), + $meta + ); $transferLazyDto = app(TransferLazyDtoAssemblerInterface::class)->create( $this, $to, diff --git a/src/Traits/CanPay.php b/src/Traits/CanPay.php index 6971bd3ab..4039eed38 100644 --- a/src/Traits/CanPay.php +++ b/src/Traits/CanPay.php @@ -38,12 +38,12 @@ trait CanPay */ public function payFree(Product $product): Transfer { - return current($this->payFreeCart(app(Cart::class)->addItem($product))); + return current($this->payFreeCart(app(Cart::class)->withItem($product))); } public function safePay(Product $product, bool $force = false): ?Transfer { - return current($this->safePayCart(app(Cart::class)->addItem($product), $force)) ?: null; + return current($this->safePayCart(app(Cart::class)->withItem($product), $force)) ?: null; } /** @@ -58,7 +58,7 @@ public function safePay(Product $product, bool $force = false): ?Transfer */ public function pay(Product $product, bool $force = false): Transfer { - return current($this->payCart(app(Cart::class)->addItem($product), $force)); + return current($this->payCart(app(Cart::class)->withItem($product), $force)); } /** @@ -71,12 +71,12 @@ public function pay(Product $product, bool $force = false): Transfer */ public function forcePay(Product $product): Transfer { - return current($this->forcePayCart(app(Cart::class)->addItem($product))); + return current($this->forcePayCart(app(Cart::class)->withItem($product))); } public function safeRefund(Product $product, bool $force = false, bool $gifts = false): bool { - return $this->safeRefundCart(app(Cart::class)->addItem($product), $force, $gifts); + return $this->safeRefundCart(app(Cart::class)->withItem($product), $force, $gifts); } /** @@ -91,7 +91,7 @@ public function safeRefund(Product $product, bool $force = false, bool $gifts = */ public function refund(Product $product, bool $force = false, bool $gifts = false): bool { - return $this->refundCart(app(Cart::class)->addItem($product), $force, $gifts); + return $this->refundCart(app(Cart::class)->withItem($product), $force, $gifts); } /** @@ -104,12 +104,12 @@ public function refund(Product $product, bool $force = false, bool $gifts = fals */ public function forceRefund(Product $product, bool $gifts = false): bool { - return $this->forceRefundCart(app(Cart::class)->addItem($product), $gifts); + return $this->forceRefundCart(app(Cart::class)->withItem($product), $gifts); } public function safeRefundGift(Product $product, bool $force = false): bool { - return $this->safeRefundGiftCart(app(Cart::class)->addItem($product), $force); + return $this->safeRefundGiftCart(app(Cart::class)->withItem($product), $force); } /** @@ -124,7 +124,7 @@ public function safeRefundGift(Product $product, bool $force = false): bool */ public function refundGift(Product $product, bool $force = false): bool { - return $this->refundGiftCart(app(Cart::class)->addItem($product), $force); + return $this->refundGiftCart(app(Cart::class)->withItem($product), $force); } /** @@ -137,6 +137,6 @@ public function refundGift(Product $product, bool $force = false): bool */ public function forceRefundGift(Product $product): bool { - return $this->forceRefundGiftCart(app(Cart::class)->addItem($product)); + return $this->forceRefundGiftCart(app(Cart::class)->withItem($product)); } } diff --git a/src/Traits/CartPay.php b/src/Traits/CartPay.php index e1dc672d1..be53d68fa 100644 --- a/src/Traits/CartPay.php +++ b/src/Traits/CartPay.php @@ -80,7 +80,9 @@ public function payFreeCart(CartInterface $cart): array }); } - /** @return Transfer[] */ + /** + * @return Transfer[] + */ public function safePayCart(CartInterface $cart, bool $force = false): array { try { @@ -176,7 +178,8 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts $transfers = app(PurchaseServiceInterface::class)->already($this, $cart->getBasketDto(), $gifts); if (count($transfers) !== $cart->getBasketDto()->total()) { throw new ModelNotFoundException( - "No query results for model [{$this->transfers()->getMorphClass()}]", + "No query results for model [{$this->transfers() + ->getMorphClass()}]", ExceptionInterface::MODEL_NOT_FOUND ); } @@ -187,8 +190,8 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts $transfer = current($transfers); next($transfers); /** - * the code is extremely poorly written, a complete refactoring is required. - * for version 6.x we will leave it as it is. + * the code is extremely poorly written, a complete refactoring is required. for version 6.x we will + * leave it as it is. */ $transfer->load('withdraw.wallet'); // fixme: need optimize @@ -274,7 +277,7 @@ public function forceRefundGiftCart(CartInterface $cart): bool */ public function paid(Product $product, bool $gifts = false): ?Transfer { - $cart = app(Cart::class)->addItem($product); + $cart = app(Cart::class)->withItem($product); $purchases = app(PurchaseServiceInterface::class) ->already($this, $cart->getBasketDto(), $gifts) ; diff --git a/src/Traits/HasGift.php b/src/Traits/HasGift.php index 60d5a83e8..d7ea425b0 100644 --- a/src/Traits/HasGift.php +++ b/src/Traits/HasGift.php @@ -32,7 +32,9 @@ */ trait HasGift { - /** Give the goods safely. */ + /** + * Give the goods safely. + */ public function safeGift(Wallet $to, Product $product, bool $force = false): ?Transfer { try { @@ -43,9 +45,8 @@ public function safeGift(Wallet $to, Product $product, bool $force = false): ?Tr } /** - * From this moment on, each user (wallet) can give - * the goods to another user (wallet). - * This functionality can be organized for gifts. + * From this moment on, each user (wallet) can give the goods to another user (wallet). This functionality can be + * organized for gifts. * * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -68,7 +69,12 @@ public function gift(Wallet $to, Product $product, bool $force = false): Transfe $commonService = app(CommonServiceLegacy::class); $metaProduct = $product->getMetaProduct(); - $withdraw = $commonService->makeTransaction($this, Transaction::TYPE_WITHDRAW, $mathService->add($amount, $fee), $metaProduct); + $withdraw = $commonService->makeTransaction( + $this, + Transaction::TYPE_WITHDRAW, + $mathService->add($amount, $fee), + $metaProduct + ); $deposit = $commonService->makeTransaction($product, Transaction::TYPE_DEPOSIT, $amount, $metaProduct); $castService = app(CastServiceInterface::class); diff --git a/src/Traits/HasWallet.php b/src/Traits/HasWallet.php index ff7e5dc1c..01102d459 100644 --- a/src/Traits/HasWallet.php +++ b/src/Traits/HasWallet.php @@ -61,34 +61,14 @@ public function deposit($amount, ?array $meta = null, bool $confirmed = true): T } /** - * Magic laravel framework method, makes it - * possible to call property balance. - * - * Example: - * $user1 = User::first()->load('wallet'); - * $user2 = User::first()->load('wallet'); - * - * Without static: - * var_dump($user1->balance, $user2->balance); // 100 100 - * $user1->deposit(100); - * $user2->deposit(100); - * var_dump($user1->balance, $user2->balance); // 200 200 - * - * With static: - * var_dump($user1->balance, $user2->balance); // 100 100 - * $user1->deposit(100); - * var_dump($user1->balance); // 200 - * $user2->deposit(100); - * var_dump($user2->balance); // 300 + * Magic laravel framework method, makes it possible to call property balance. * * @return float|int|string */ public function getBalanceAttribute() { /** @var Wallet $this */ - return app(RegulatorServiceInterface::class)->amount( - app(CastServiceInterface::class)->getWallet($this) - ); + return app(RegulatorServiceInterface::class)->amount(app(CastServiceInterface::class)->getWallet($this)); } public function getBalanceIntAttribute(): int @@ -209,8 +189,8 @@ public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = tr } /** - * the forced transfer is needed when the user does not have the money and we drive it. - * Sometimes you do. Depends on business logic. + * the forced transfer is needed when the user does not have the money, and we drive it. Sometimes you do. Depends + * on business logic. * * @param int|string $amount * @@ -230,8 +210,7 @@ public function forceTransfer(Wallet $wallet, $amount, ?array $meta = null): Tra } /** - * the transfer table is used to confirm the payment - * this method receives all transfers. + * the transfer table is used to confirm the payment this method receives all transfers. */ public function transfers(): MorphMany { diff --git a/src/Traits/HasWallets.php b/src/Traits/HasWallets.php index 4e31b903d..de46935e0 100644 --- a/src/Traits/HasWallets.php +++ b/src/Traits/HasWallets.php @@ -13,8 +13,7 @@ use Illuminate\Support\Collection; /** - * Trait HasWallets - * To use a trait, you must add HasWallet trait. + * Trait HasWallets To use a trait, you must add HasWallet trait. * * @property Collection|WalletModel[] $wallets * @psalm-require-extends \Illuminate\Database\Eloquent\Model @@ -22,9 +21,8 @@ trait HasWallets { /** - * The variable is used for the cache, so as not to request wallets many times. - * WalletProxy keeps the money wallets in the memory to avoid errors when you - * purchase/transfer, etc. + * The variable is used for the cache, so as not to request wallets many times. WalletProxy keeps the money wallets + * in the memory to avoid errors when you purchase/transfer, etc. */ private array $_wallets = []; @@ -33,14 +31,11 @@ trait HasWallets /** * Get wallet by slug. * - * $user->wallet->balance // 200 - * or short recording $user->balance; // 200 + * $user->wallet->balance // 200 or short recording $user->balance; // 200 * - * $defaultSlug = config('wallet.wallet.default.slug'); - * $user->getWallet($defaultSlug)->balance; // 200 + * $defaultSlug = config('wallet.wallet.default.slug'); $user->getWallet($defaultSlug)->balance; // 200 * - * $user->getWallet('usd')->balance; // 50 - * $user->getWallet('rub')->balance; // 100 + * $user->getWallet('usd')->balance; // 50 $user->getWallet('rub')->balance; // 100 */ public function getWallet(string $slug): ?WalletModel { @@ -54,14 +49,11 @@ public function getWallet(string $slug): ?WalletModel /** * Get wallet by slug. * - * $user->wallet->balance // 200 - * or short recording $user->balance; // 200 + * $user->wallet->balance // 200 or short recording $user->balance; // 200 * - * $defaultSlug = config('wallet.wallet.default.slug'); - * $user->getWallet($defaultSlug)->balance; // 200 + * $defaultSlug = config('wallet.wallet.default.slug'); $user->getWallet($defaultSlug)->balance; // 200 * - * $user->getWallet('usd')->balance; // 50 - * $user->getWallet('rub')->balance; // 100 + * $user->getWallet('usd')->balance; // 50 $user->getWallet('rub')->balance; // 100 * * @throws ModelNotFoundException */ diff --git a/src/Traits/MorphOneWallet.php b/src/Traits/MorphOneWallet.php index 2d3a53d7d..4dbf2a5d0 100644 --- a/src/Traits/MorphOneWallet.php +++ b/src/Traits/MorphOneWallet.php @@ -17,8 +17,7 @@ trait MorphOneWallet { /** - * Get default Wallet - * this method is used for Eager Loading. + * Get default Wallet this method is used for Eager Loading. */ public function wallet(): MorphOne { diff --git a/src/WalletConfigure.php b/src/WalletConfigure.php index 551867e2a..c357278db 100644 --- a/src/WalletConfigure.php +++ b/src/WalletConfigure.php @@ -13,13 +13,17 @@ final class WalletConfigure { private static bool $runsMigrations = true; - /** Configure Wallet to not register its migrations. */ + /** + * Configure Wallet to not register its migrations. + */ public static function ignoreMigrations(): void { self::$runsMigrations = false; } - /** Indicates if Wallet migrations will be run. */ + /** + * Indicates if Wallet migrations will be run. + */ public static function isRunsMigrations(): bool { return self::$runsMigrations; diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index 44658b1a8..d34c796e7 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -100,10 +100,7 @@ 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; @@ -129,10 +126,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'); $configure = config('wallet', []); @@ -160,10 +154,7 @@ private function repositories(array $configure): void $configure['transfer'] ?? TransferRepository::class ); - $this->app->singleton( - WalletRepositoryInterface::class, - $configure['wallet'] ?? WalletRepository::class - ); + $this->app->singleton(WalletRepositoryInterface::class, $configure['wallet'] ?? WalletRepository::class); } /** @@ -195,7 +186,10 @@ private function services(array $configure, array $cache): void $this->app->singleton(AtomicServiceInterface::class, $configure['atomic'] ?? AtomicService::class); $this->app->singleton(BasketServiceInterface::class, $configure['basket'] ?? BasketService::class); $this->app->singleton(CastServiceInterface::class, $configure['cast'] ?? CastService::class); - $this->app->singleton(ConsistencyServiceInterface::class, $configure['consistency'] ?? ConsistencyService::class); + $this->app->singleton( + ConsistencyServiceInterface::class, + $configure['consistency'] ?? ConsistencyService::class + ); $this->app->singleton(DiscountServiceInterface::class, $configure['discount'] ?? DiscountService::class); $this->app->singleton(ExchangeServiceInterface::class, $configure['exchange'] ?? ExchangeService::class); $this->app->singleton(PrepareServiceInterface::class, $configure['prepare'] ?? PrepareService::class); diff --git a/tests/Infra/Factories/BuyerFactory.php b/tests/Infra/Factories/BuyerFactory.php index 7737cece4..b7325165c 100644 --- a/tests/Infra/Factories/BuyerFactory.php +++ b/tests/Infra/Factories/BuyerFactory.php @@ -23,7 +23,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/ManagerFactory.php b/tests/Infra/Factories/ManagerFactory.php index 7deee3e23..54b0c72ad 100644 --- a/tests/Infra/Factories/ManagerFactory.php +++ b/tests/Infra/Factories/ManagerFactory.php @@ -27,7 +27,8 @@ public function definition(): array return [ 'id' => Uuid::uuid4()->toString(), 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/UserCashierFactory.php b/tests/Infra/Factories/UserCashierFactory.php index 308a76110..ca6236b97 100644 --- a/tests/Infra/Factories/UserCashierFactory.php +++ b/tests/Infra/Factories/UserCashierFactory.php @@ -25,7 +25,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/UserConfirmFactory.php b/tests/Infra/Factories/UserConfirmFactory.php index 3215b9684..d277be651 100644 --- a/tests/Infra/Factories/UserConfirmFactory.php +++ b/tests/Infra/Factories/UserConfirmFactory.php @@ -25,7 +25,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/UserFactory.php b/tests/Infra/Factories/UserFactory.php index 1b2e53ade..985edd99d 100644 --- a/tests/Infra/Factories/UserFactory.php +++ b/tests/Infra/Factories/UserFactory.php @@ -25,7 +25,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/UserFloatFactory.php b/tests/Infra/Factories/UserFloatFactory.php index 5cd7f44e0..97699f3a1 100644 --- a/tests/Infra/Factories/UserFloatFactory.php +++ b/tests/Infra/Factories/UserFloatFactory.php @@ -25,7 +25,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Factories/UserMultiFactory.php b/tests/Infra/Factories/UserMultiFactory.php index 3cc51d03d..13ddc9497 100644 --- a/tests/Infra/Factories/UserMultiFactory.php +++ b/tests/Infra/Factories/UserMultiFactory.php @@ -25,7 +25,8 @@ public function definition(): array { return [ 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, + 'email' => $this->faker->unique() + ->safeEmail, ]; } } diff --git a/tests/Infra/Listeners/BalanceUpdatedThrowDateListener.php b/tests/Infra/Listeners/BalanceUpdatedThrowDateListener.php index ecc0652c5..b5abc05b7 100644 --- a/tests/Infra/Listeners/BalanceUpdatedThrowDateListener.php +++ b/tests/Infra/Listeners/BalanceUpdatedThrowDateListener.php @@ -13,7 +13,8 @@ final class BalanceUpdatedThrowDateListener public function handle(BalanceUpdatedEventInterface $balanceChangedEvent): void { throw new UnknownEventException( - $balanceChangedEvent->getUpdatedAt()->format(DateTimeInterface::ATOM), + $balanceChangedEvent->getUpdatedAt() + ->format(DateTimeInterface::ATOM), (int) $balanceChangedEvent->getBalance() ); } diff --git a/tests/Infra/Listeners/BalanceUpdatedThrowIdListener.php b/tests/Infra/Listeners/BalanceUpdatedThrowIdListener.php index e78588320..a668f494b 100644 --- a/tests/Infra/Listeners/BalanceUpdatedThrowIdListener.php +++ b/tests/Infra/Listeners/BalanceUpdatedThrowIdListener.php @@ -11,6 +11,9 @@ final class BalanceUpdatedThrowIdListener { public function handle(BalanceUpdatedEventInterface $balanceChangedEvent): void { - throw new UnknownEventException((string) $balanceChangedEvent->getWalletId(), (int) $balanceChangedEvent->getBalance()); + throw new UnknownEventException( + (string) $balanceChangedEvent->getWalletId(), + (int) $balanceChangedEvent->getBalance() + ); } } diff --git a/tests/Infra/Listeners/BalanceUpdatedThrowUuidListener.php b/tests/Infra/Listeners/BalanceUpdatedThrowUuidListener.php index a4769ccf2..526da4314 100644 --- a/tests/Infra/Listeners/BalanceUpdatedThrowUuidListener.php +++ b/tests/Infra/Listeners/BalanceUpdatedThrowUuidListener.php @@ -11,6 +11,9 @@ final class BalanceUpdatedThrowUuidListener { public function handle(BalanceUpdatedEventInterface $balanceChangedEvent): void { - throw new UnknownEventException($balanceChangedEvent->getWalletUuid(), (int) $balanceChangedEvent->getBalance()); + throw new UnknownEventException( + $balanceChangedEvent->getWalletUuid(), + (int) $balanceChangedEvent->getBalance() + ); } } diff --git a/tests/Infra/Listeners/WalletCreatedThrowListener.php b/tests/Infra/Listeners/WalletCreatedThrowListener.php index 8f85195cb..80e72996c 100644 --- a/tests/Infra/Listeners/WalletCreatedThrowListener.php +++ b/tests/Infra/Listeners/WalletCreatedThrowListener.php @@ -14,7 +14,9 @@ public function handle(WalletCreatedEventInterface $walletCreatedEvent): void { $holderType = $walletCreatedEvent->getHolderType(); $uuid = $walletCreatedEvent->getWalletUuid(); - $createdAt = $walletCreatedEvent->getCreatedAt()->format(DateTimeInterface::ATOM); + $createdAt = $walletCreatedEvent->getCreatedAt() + ->format(DateTimeInterface::ATOM) + ; $message = hash('sha256', $holderType.$uuid.$createdAt); $code = $walletCreatedEvent->getWalletId() + $walletCreatedEvent->getHolderId(); diff --git a/tests/Infra/Models/ItemDiscountTax.php b/tests/Infra/Models/ItemDiscountTax.php index 3c85d629d..6548433e1 100644 --- a/tests/Infra/Models/ItemDiscountTax.php +++ b/tests/Infra/Models/ItemDiscountTax.php @@ -9,12 +9,9 @@ class ItemDiscountTax extends ItemDiscount implements Taxable { /** - * Specify the percentage of the amount. - * For example, the product costs $100, the equivalent of 15%. - * That's $115. + * Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115. * - * Minimum 0; Maximum 100 - * Example: return 7.5; // 7.5% + * Minimum 0; Maximum 100 Example: return 7.5; // 7.5% */ public function getFeePercent(): float { diff --git a/tests/Infra/Models/ItemMeta.php b/tests/Infra/Models/ItemMeta.php index 78b22d124..8033ddb43 100644 --- a/tests/Infra/Models/ItemMeta.php +++ b/tests/Infra/Models/ItemMeta.php @@ -13,6 +13,9 @@ public function getTable(): string public function getMetaProduct(): ?array { - return ['name' => $this->name, 'price' => $this->price]; + return [ + 'name' => $this->name, + 'price' => $this->price, + ]; } } diff --git a/tests/Infra/Models/ItemTax.php b/tests/Infra/Models/ItemTax.php index c5df3e044..fe74e6d23 100644 --- a/tests/Infra/Models/ItemTax.php +++ b/tests/Infra/Models/ItemTax.php @@ -14,12 +14,9 @@ public function getTable(): string } /** - * Specify the percentage of the amount. - * For example, the product costs $100, the equivalent of 15%. - * That's $115. + * Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115. * - * Minimum 0; Maximum 100 - * Example: return 7.5; // 7.5% + * Minimum 0; Maximum 100 Example: return 7.5; // 7.5% * * @return float|int */ diff --git a/tests/Infra/MyExchangeService.php b/tests/Infra/MyExchangeService.php index 4aad8baa5..36f42e9a3 100644 --- a/tests/Infra/MyExchangeService.php +++ b/tests/Infra/MyExchangeService.php @@ -15,11 +15,9 @@ class MyExchangeService implements ExchangeServiceInterface ], ]; - /** - * Rate constructor. - */ - public function __construct(private MathServiceInterface $mathService) - { + public function __construct( + private MathServiceInterface $mathService + ) { foreach ($this->rates as $from => $rates) { foreach ($rates as $to => $rate) { if (empty($this->rates[$to][$from])) { @@ -29,7 +27,9 @@ public function __construct(private MathServiceInterface $mathService) } } - /** @param float|int|string $amount */ + /** + * @param float|int|string $amount + */ public function convertTo(string $fromCurrency, string $toCurrency, $amount): string { return $this->mathService->mul($amount, $this->rates[$fromCurrency][$toCurrency] ?? 1); diff --git a/tests/Infra/PackageModels/Transaction.php b/tests/Infra/PackageModels/Transaction.php index 53001886b..ca122706d 100644 --- a/tests/Infra/PackageModels/Transaction.php +++ b/tests/Infra/PackageModels/Transaction.php @@ -16,8 +16,6 @@ class Transaction extends \Bavix\Wallet\Models\Transaction */ public function getFillable(): array { - return array_merge($this->fillable, [ - 'bank_method', - ]); + return array_merge($this->fillable, ['bank_method']); } } diff --git a/tests/Infra/TestCase.php b/tests/Infra/TestCase.php index 0c31da1be..f24add7a8 100644 --- a/tests/Infra/TestCase.php +++ b/tests/Infra/TestCase.php @@ -17,7 +17,7 @@ /** * @internal */ -class TestCase extends OrchestraTestCase +abstract class TestCase extends OrchestraTestCase { use RefreshDatabase; @@ -45,10 +45,7 @@ protected function getPackageProviders($app): array $app['config']->set('wallet.transfer.model', Transfer::class); $app['config']->set('wallet.wallet.model', Wallet::class); - return [ - WalletServiceProvider::class, - TestServiceProvider::class, - ]; + return [WalletServiceProvider::class, TestServiceProvider::class]; } /** @@ -65,7 +62,9 @@ protected function getEnvironmentSetUp($app): void $config->set('database.connections.mysql.prefix', 'tests'); $mysql = $config->get('database.connections.mysql'); - $config->set('database.connections.mariadb', array_merge($mysql, ['port' => 3307])); + $config->set('database.connections.mariadb', array_merge($mysql, [ + 'port' => 3307, + ])); // new table name's $config->set('wallet.transaction.table', 'transaction'); diff --git a/tests/Infra/Transform/TransactionDtoTransformerCustom.php b/tests/Infra/Transform/TransactionDtoTransformerCustom.php index e2e69fd46..cc82230db 100644 --- a/tests/Infra/Transform/TransactionDtoTransformerCustom.php +++ b/tests/Infra/Transform/TransactionDtoTransformerCustom.php @@ -10,8 +10,9 @@ final class TransactionDtoTransformerCustom implements TransactionDtoTransformerInterface { - public function __construct(private TransactionDtoTransformer $transactionDtoTransformer) - { + public function __construct( + private TransactionDtoTransformer $transactionDtoTransformer + ) { } public function extract(TransactionDtoInterface $dto): array diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index b113ffee1..442b45f75 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -17,7 +17,7 @@ /** * @internal */ -class BalanceTest extends TestCase +final class BalanceTest extends TestCase { public function testDepositWalletExists(): void { @@ -111,7 +111,10 @@ public function testSimple(): void $result = app(RegulatorServiceInterface::class)->increase($wallet, 100); // databases that do not support fk will not delete data... need to help them - $wallet->transactions()->where('wallet_id', $key)->delete(); + $wallet->transactions() + ->where('wallet_id', $key) + ->delete() + ; self::assertFalse($wallet->exists); self::assertSame(1100, (int) $result); @@ -160,16 +163,31 @@ public function testThrowUpdate(): void /** @var MockObject|Wallet $mockQuery */ $mockQuery = $this->createMock($wallet->newQuery()::class); - $mockQuery->method('whereKey')->willReturn($mockQuery); - $mockQuery->method('update')->willThrowException(new PDOException()); + $mockQuery->method('whereKey') + ->willReturn($mockQuery) + ; + $mockQuery->method('update') + ->willThrowException(new PDOException()) + ; /** @var MockObject|Wallet $mockWallet */ $mockWallet = $this->createMock($wallet::class); - $mockWallet->method('getBalanceAttribute')->willReturn('125'); - $mockWallet->method('newQuery')->willReturn($mockQuery); - $mockWallet->method('getKey')->willReturn($wallet->getKey()); - - $mockWallet->newQuery()->whereKey($wallet->getKey())->update(['balance' => 100]); + $mockWallet->method('getBalanceAttribute') + ->willReturn('125') + ; + $mockWallet->method('newQuery') + ->willReturn($mockQuery) + ; + $mockWallet->method('getKey') + ->willReturn($wallet->getKey()) + ; + + $mockWallet->newQuery() + ->whereKey($wallet->getKey()) + ->update([ + 'balance' => 100, + ]) + ; } public function testEqualWallet(): void diff --git a/tests/Units/Domain/BasketTest.php b/tests/Units/Domain/BasketTest.php index 73bf01e9b..747121325 100644 --- a/tests/Units/Domain/BasketTest.php +++ b/tests/Units/Domain/BasketTest.php @@ -12,7 +12,7 @@ /** * @internal */ -class BasketTest extends TestCase +final class BasketTest extends TestCase { public function testCount(): void { @@ -38,8 +38,12 @@ public function testMeta(): void $basket1 = new BasketDto([], []); self::assertEmpty($basket1->meta()); - $basket2 = new BasketDto([], ['hello' => 'world']); - self::assertSame(['hello' => 'world'], $basket2->meta()); + $basket2 = new BasketDto([], [ + 'hello' => 'world', + ]); + self::assertSame([ + 'hello' => 'world', + ], $basket2->meta()); } public function testEmpty(): void diff --git a/tests/Units/Domain/CartTest.php b/tests/Units/Domain/CartTest.php index 147e1165a..fde6d948d 100644 --- a/tests/Units/Domain/CartTest.php +++ b/tests/Units/Domain/CartTest.php @@ -24,7 +24,7 @@ /** * @internal */ -class CartTest extends TestCase +final class CartTest extends TestCase { public function testCartMeta(): void { @@ -40,8 +40,10 @@ public function testCartMeta(): void $expected = 'pay'; $cart = app(Cart::class) - ->addItems([$product]) - ->setMeta(['type' => $expected]) + ->withItems([$product]) + ->withMeta([ + 'type' => $expected, + ]) ; self::assertSame(0, $buyer->balanceInt); @@ -82,8 +84,10 @@ public function testCartMetaItemNoMeta(): void $expected = 'pay'; $cart = app(Cart::class) - ->addItems([$product]) - ->setMeta(['type' => $expected]) + ->withItems([$product]) + ->withMeta([ + 'type' => $expected, + ]) ; self::assertSame(0, $buyer->balanceInt); @@ -113,7 +117,7 @@ public function testPay(): void 'quantity' => 1, ]); - $cart = app(Cart::class)->addItems($products); + $cart = app(Cart::class)->withItems($products); foreach ($cart->getItems() as $product) { self::assertSame(0, $product->getBalanceIntAttribute()); } @@ -161,7 +165,7 @@ public function testCartQuantity(): void $price = 0; for ($i = 0; $i < count($products) - 1; ++$i) { $rnd = random_int(1, 5); - $cart->addItem($products[$i], $rnd); + $cart = $cart->withItem($products[$i], $rnd); $price += $products[$i]->getAmountProduct($buyer) * $rnd; $amount += $rnd; } @@ -195,7 +199,7 @@ public function testModelNotFoundException(): void $total = 0; for ($i = 0; $i < count($products) - 1; ++$i) { $rnd = random_int(1, 5); - $cart->addItem($products[$i], $rnd); + $cart = $cart->withItem($products[$i], $rnd); $buyer->deposit($products[$i]->getAmountProduct($buyer) * $rnd); $total += $rnd; } @@ -209,7 +213,7 @@ public function testModelNotFoundException(): void self::assertCount($total, $transfers); $refundCart = app(Cart::class) - ->addItems($products) // all goods + ->withItems($products) // all goods ; $buyer->refundCart($refundCart); @@ -233,7 +237,7 @@ public function testBoughtGoods(): void $total = []; foreach ($products as $product) { $quantity = random_int(1, 5); - $cart->addItem($product, $quantity); + $cart = $cart->withItem($product, $quantity); $buyer->deposit($product->getAmountProduct($buyer) * $quantity); $total[$product->getKey()] = $quantity; } @@ -264,10 +268,11 @@ public function testWithdrawal(): void * @var Item $product */ $buyer = BuyerFactory::new()->create(); - $product = ItemFactory::new()->create(['quantity' => 1]); + $product = ItemFactory::new()->create([ + 'quantity' => 1, + ]); - $cart = app(Cart::class); - $cart->addItem($product, 1); + $cart = app(Cart::class)->withItem($product, 1); foreach ($cart->getItems() as $item) { self::assertSame(0, $item->getBalanceIntAttribute()); diff --git a/tests/Units/Domain/ConfirmTest.php b/tests/Units/Domain/ConfirmTest.php index f13cbc56d..c9088d307 100644 --- a/tests/Units/Domain/ConfirmTest.php +++ b/tests/Units/Domain/ConfirmTest.php @@ -22,7 +22,7 @@ /** * @internal */ -class ConfirmTest extends TestCase +final class ConfirmTest extends TestCase { public function testSimple(): void { @@ -32,7 +32,9 @@ public function testSimple(): void self::assertSame(0, $wallet->balanceInt); - $transaction = $wallet->deposit(1000, ['desc' => 'unconfirmed'], false); + $transaction = $wallet->deposit(1000, [ + 'desc' => 'unconfirmed', + ], false); self::assertTrue($transaction->getKey() > 0); self::assertSame(0, $wallet->balanceInt); self::assertFalse($transaction->confirmed); @@ -53,7 +55,9 @@ public function testSafe(): void self::assertSame(0, $wallet->balanceInt); - $transaction = $wallet->forceWithdraw(1000, ['desc' => 'unconfirmed'], false); + $transaction = $wallet->forceWithdraw(1000, [ + 'desc' => 'unconfirmed', + ], false); self::assertSame(0, $wallet->balanceInt); self::assertFalse($transaction->confirmed); self::assertTrue($transaction->getKey() > 0); @@ -71,7 +75,9 @@ public function testSafeResetConfirm(): void self::assertSame(0, $wallet->balanceInt); - $transaction = $wallet->forceWithdraw(1000, ['desc' => 'confirmed']); + $transaction = $wallet->forceWithdraw(1000, [ + 'desc' => 'confirmed', + ]); self::assertSame(-1000, $wallet->balanceInt); self::assertTrue($transaction->confirmed); @@ -95,7 +101,9 @@ public function testWithdraw(): void self::assertSame(100, $wallet->balanceInt); - $transaction = $wallet->withdraw(50, ['desc' => 'unconfirmed'], false); + $transaction = $wallet->withdraw(50, [ + 'desc' => 'unconfirmed', + ], false); self::assertSame(100, $wallet->balanceInt); self::assertFalse($transaction->confirmed); } @@ -108,7 +116,9 @@ public function testForce(): void self::assertSame(0, $wallet->balanceInt); - $transaction = $wallet->forceWithdraw(1000, ['desc' => 'unconfirmed'], false); + $transaction = $wallet->forceWithdraw(1000, [ + 'desc' => 'unconfirmed', + ], false); self::assertSame(0, $wallet->balanceInt); self::assertFalse($transaction->confirmed); @@ -125,7 +135,9 @@ public function testUnconfirmed(): void self::assertSame(0, $wallet->balanceInt); - $transaction = $wallet->forceWithdraw(1000, ['desc' => 'confirmed']); + $transaction = $wallet->forceWithdraw(1000, [ + 'desc' => 'confirmed', + ]); self::assertSame(-1000, $wallet->balanceInt); self::assertTrue($transaction->confirmed); @@ -202,7 +214,9 @@ public function testWalletOwnerInvalid(): void self::assertSame(0, $firstWallet->balanceInt); - $transaction = $firstWallet->deposit(1000, ['desc' => 'unconfirmed'], false); + $transaction = $firstWallet->deposit(1000, [ + 'desc' => 'unconfirmed', + ], false); self::assertSame(0, $firstWallet->balanceInt); self::assertFalse($transaction->confirmed); diff --git a/tests/Units/Domain/CreditWalletTest.php b/tests/Units/Domain/CreditWalletTest.php index 9fd918c5f..bc64b023c 100644 --- a/tests/Units/Domain/CreditWalletTest.php +++ b/tests/Units/Domain/CreditWalletTest.php @@ -11,7 +11,7 @@ /** * @internal */ -class CreditWalletTest extends TestCase +final class CreditWalletTest extends TestCase { public function testCreditLimit(): void { @@ -20,7 +20,10 @@ public function testCreditLimit(): void $wallet = $user->createWallet([ 'name' => 'Credit USD', 'slug' => 'credit-usd', - 'meta' => ['credit' => 10000, 'currency' => 'USD'], + 'meta' => [ + 'credit' => 10000, + 'currency' => 'USD', + ], ]); $transaction = $wallet->deposit(1000); @@ -41,7 +44,10 @@ public function testCreditLimitBalanceZero(): void $wallet = $user->createWallet([ 'name' => 'Credit USD', 'slug' => 'credit-usd', - 'meta' => ['credit' => 10000, 'currency' => 'USD'], + 'meta' => [ + 'credit' => 10000, + 'currency' => 'USD', + ], ]); self::assertSame(0, $wallet->balanceInt); diff --git a/tests/Units/Domain/DiscountTaxTest.php b/tests/Units/Domain/DiscountTaxTest.php index 3b9a44d8d..e8bb8e6da 100644 --- a/tests/Units/Domain/DiscountTaxTest.php +++ b/tests/Units/Domain/DiscountTaxTest.php @@ -21,7 +21,7 @@ /** * @internal */ -class DiscountTaxTest extends TestCase +final class DiscountTaxTest extends TestCase { public function testPay(): void { @@ -41,15 +41,9 @@ public function testPay(): void self::assertNotNull($transfer); self::assertSame(Transfer::STATUS_PAID, $transfer->status); - self::assertSame( - $buyer->balanceInt, - $product->getPersonalDiscount($buyer) - ); + self::assertSame($buyer->balanceInt, $product->getPersonalDiscount($buyer)); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); self::assertSame((int) $transfer->fee, (int) $fee); @@ -98,10 +92,7 @@ public function testRefundPersonalDiscountAndTax(): void self::assertNotNull($transfer); self::assertSame($transfer->status, Transfer::STATUS_PAID); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); self::assertSame((int) $transfer->fee, (int) $fee); @@ -166,15 +157,9 @@ public function testForceRefund(): void $transfer = $buyer->pay($product); self::assertSame(0, $buyer->balanceInt); - self::assertSame( - $product->balanceInt, - (int) -$transfer->withdraw->amount - $fee - ); + self::assertSame($product->balanceInt, (int) -$transfer->withdraw->amount - $fee); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); self::assertSame((int) $transfer->fee, (int) $fee); @@ -286,10 +271,7 @@ public function testFreePay(): void self::assertSame($transfer->deposit->type, Transaction::TYPE_DEPOSIT); self::assertSame($transfer->withdraw->type, Transaction::TYPE_WITHDRAW); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); self::assertSame(0, (int) $transfer->fee); diff --git a/tests/Units/Domain/DiscountTest.php b/tests/Units/Domain/DiscountTest.php index f1cc5b580..f5ab87eb2 100644 --- a/tests/Units/Domain/DiscountTest.php +++ b/tests/Units/Domain/DiscountTest.php @@ -19,7 +19,7 @@ /** * @internal */ -class DiscountTest extends TestCase +final class DiscountTest extends TestCase { public function testPay(): void { @@ -38,15 +38,9 @@ public function testPay(): void self::assertNotNull($transfer); self::assertSame(Transfer::STATUS_PAID, $transfer->status); - self::assertSame( - $buyer->balanceInt, - $product->getPersonalDiscount($buyer) - ); + self::assertSame($buyer->balanceInt, $product->getPersonalDiscount($buyer)); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); /** * @var Transaction $withdraw @@ -91,15 +85,9 @@ public function testItemTransactions(): void self::assertNotNull($transfer); self::assertSame(Transfer::STATUS_PAID, $transfer->status); - self::assertSame( - $buyer->balanceInt, - $product->getPersonalDiscount($buyer) - ); + self::assertSame($buyer->balanceInt, $product->getPersonalDiscount($buyer)); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); /** * @var Transaction $withdraw @@ -140,10 +128,7 @@ public function testRefund(): void self::assertNotNull($transfer); self::assertSame(Transfer::STATUS_PAID, $transfer->status); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); self::assertTrue($buyer->refund($product)); self::assertSame($buyer->balanceInt, (int) $product->getAmountProduct($buyer)); @@ -197,10 +182,7 @@ public function testForceRefund(): void (int) ($product->getAmountProduct($buyer) - $product->getPersonalDiscount($buyer)) ); - self::assertSame( - (int) $transfer->discount, - $product->getPersonalDiscount($buyer) - ); + self::assertSame((int) $transfer->discount, $product->getPersonalDiscount($buyer)); $product->withdraw($product->balance); self::assertSame(0, $product->balanceInt); diff --git a/tests/Units/Domain/EagerLoadingTest.php b/tests/Units/Domain/EagerLoadingTest.php index 55c379881..fb0720eb4 100644 --- a/tests/Units/Domain/EagerLoadingTest.php +++ b/tests/Units/Domain/EagerLoadingTest.php @@ -11,7 +11,7 @@ /** * @internal */ -class EagerLoadingTest extends TestCase +final class EagerLoadingTest extends TestCase { public function testUuidDuplicate(): void { diff --git a/tests/Units/Domain/EventTest.php b/tests/Units/Domain/EventTest.php index 309db3e96..82f231d7b 100644 --- a/tests/Units/Domain/EventTest.php +++ b/tests/Units/Domain/EventTest.php @@ -25,7 +25,7 @@ /** * @internal */ -class EventTest extends TestCase +final class EventTest extends TestCase { public function testBalanceUpdatedThrowUuidListener(): void { diff --git a/tests/Units/Domain/ExchangeTest.php b/tests/Units/Domain/ExchangeTest.php index 80f2bd26d..f4863a829 100644 --- a/tests/Units/Domain/ExchangeTest.php +++ b/tests/Units/Domain/ExchangeTest.php @@ -15,7 +15,7 @@ /** * @internal */ -class ExchangeTest extends TestCase +final class ExchangeTest extends TestCase { public function testSimple(): void { @@ -86,19 +86,29 @@ public function testRate(): void { /** @var UserMulti $user */ $user = UserMultiFactory::new()->create(); - $usd = $user->createWallet(['name' => 'Dollar USA', 'slug' => 'my-usd', 'meta' => ['currency' => 'USD']]); + $usd = $user->createWallet([ + 'name' => 'Dollar USA', + 'slug' => 'my-usd', + 'meta' => [ + 'currency' => 'USD', + ], + ]); self::assertSame($usd->slug, 'my-usd'); self::assertSame($usd->currency, 'USD'); self::assertSame($usd->holder_id, $user->id); self::assertInstanceOf($usd->holder_type, $user); - $rub = $user->createWallet(['name' => 'RUB']); + $rub = $user->createWallet([ + 'name' => 'RUB', + ]); self::assertSame($rub->slug, 'rub'); self::assertSame($rub->currency, 'RUB'); self::assertSame($rub->holder_id, $user->id); self::assertInstanceOf($rub->holder_type, $user); - $superWallet = $user->createWallet(['name' => 'Super Wallet']); + $superWallet = $user->createWallet([ + 'name' => 'Super Wallet', + ]); self::assertSame($superWallet->slug, Str::slug('Super Wallet')); self::assertSame($superWallet->currency, Str::upper(Str::slug('Super Wallet'))); self::assertSame($superWallet->holder_id, $user->id); diff --git a/tests/Units/Domain/GiftDiscountTaxTest.php b/tests/Units/Domain/GiftDiscountTaxTest.php index a179d3638..21b585352 100644 --- a/tests/Units/Domain/GiftDiscountTaxTest.php +++ b/tests/Units/Domain/GiftDiscountTaxTest.php @@ -15,7 +15,7 @@ /** * @internal */ -class GiftDiscountTaxTest extends TestCase +final class GiftDiscountTaxTest extends TestCase { public function testGift(): void { @@ -38,10 +38,7 @@ public function testGift(): void ); $first->deposit($product->getAmountProduct($first) + $fee); - self::assertSame( - $first->balanceInt, - (int) ($product->getAmountProduct($first) + $fee) - ); + self::assertSame($first->balanceInt, (int) ($product->getAmountProduct($first) + $fee)); $transfer = $first->wallet->gift($second, $product); self::assertSame($first->balanceInt, (int) $product->getPersonalDiscount($first)); diff --git a/tests/Units/Domain/GiftDiscountTest.php b/tests/Units/Domain/GiftDiscountTest.php index fbb74a252..d85c4852c 100644 --- a/tests/Units/Domain/GiftDiscountTest.php +++ b/tests/Units/Domain/GiftDiscountTest.php @@ -14,7 +14,7 @@ /** * @internal */ -class GiftDiscountTest extends TestCase +final class GiftDiscountTest extends TestCase { public function testGift(): void { diff --git a/tests/Units/Domain/GiftTest.php b/tests/Units/Domain/GiftTest.php index e0481efea..6fc1d1174 100644 --- a/tests/Units/Domain/GiftTest.php +++ b/tests/Units/Domain/GiftTest.php @@ -14,7 +14,7 @@ /** * @internal */ -class GiftTest extends TestCase +final class GiftTest extends TestCase { public function testGift(): void { diff --git a/tests/Units/Domain/MinTaxTest.php b/tests/Units/Domain/MinTaxTest.php index b3d75576c..4fc29821d 100644 --- a/tests/Units/Domain/MinTaxTest.php +++ b/tests/Units/Domain/MinTaxTest.php @@ -14,7 +14,7 @@ /** * @internal */ -class MinTaxTest extends TestCase +final class MinTaxTest extends TestCase { public function testPay(): void { diff --git a/tests/Units/Domain/ModelTableTest.php b/tests/Units/Domain/ModelTableTest.php index 8a409b0aa..7370b76ca 100644 --- a/tests/Units/Domain/ModelTableTest.php +++ b/tests/Units/Domain/ModelTableTest.php @@ -13,7 +13,7 @@ /** * @internal */ -class ModelTableTest extends TestCase +final class ModelTableTest extends TestCase { public function testWalletTableName(): void { diff --git a/tests/Units/Domain/MultiWalletGiftTest.php b/tests/Units/Domain/MultiWalletGiftTest.php index e320cd289..79f21ea54 100644 --- a/tests/Units/Domain/MultiWalletGiftTest.php +++ b/tests/Units/Domain/MultiWalletGiftTest.php @@ -15,7 +15,7 @@ /** * @internal */ -class MultiWalletGiftTest extends TestCase +final class MultiWalletGiftTest extends TestCase { public function testGiftWalletToUser(): void { @@ -29,7 +29,10 @@ public function testGiftWalletToUser(): void $first->deposit(1); $second->deposit(2); - $wallet = $first->createWallet(['name' => 'Gift', 'slug' => 'gifter']); + $wallet = $first->createWallet([ + 'name' => 'Gift', + 'slug' => 'gifter', + ]); self::assertNotNull($wallet); self::assertNotNull($first->wallet); self::assertNotSame((int) $first->wallet->id, (int) $wallet->id); diff --git a/tests/Units/Domain/MultiWalletTest.php b/tests/Units/Domain/MultiWalletTest.php index ae38ffe5a..7c2299b05 100644 --- a/tests/Units/Domain/MultiWalletTest.php +++ b/tests/Units/Domain/MultiWalletTest.php @@ -31,7 +31,7 @@ /** * @internal */ -class MultiWalletTest extends TestCase +final class MultiWalletTest extends TestCase { public function testCreateDefault(): void { @@ -41,7 +41,10 @@ public function testCreateDefault(): void $user = UserMultiFactory::new()->create(); self::assertNull($user->getWallet($slug)); - $wallet = $user->createWallet(['name' => 'Simple', 'slug' => $slug]); + $wallet = $user->createWallet([ + 'name' => 'Simple', + 'slug' => $slug, + ]); self::assertNotNull($wallet); self::assertNotNull($user->wallet); self::assertSame($user->wallet->id, $wallet->id); @@ -66,10 +69,7 @@ public function testOnlyCreatedWallets(): void self::assertTrue((bool) $wallet->deposit(1000)); } - self::assertEqualsCanonicalizing( - $slugs, - $user->wallets->pluck('slug')->toArray() - ); + self::assertEqualsCanonicalizing($slugs, $user->wallets->pluck('slug')->toArray()); self::assertCount(count($slugs), $user->wallets()->get()); @@ -238,8 +238,12 @@ public function testWalletTransactions(): void { /** @var UserMulti $user */ $user = UserMultiFactory::new()->create(); - $usd = $user->createWallet(['name' => 'USD']); - $eur = $user->createWallet(['name' => 'EUR']); + $usd = $user->createWallet([ + 'name' => 'USD', + ]); + $eur = $user->createWallet([ + 'name' => 'EUR', + ]); $usd->deposit(100); $eur->deposit(200); @@ -398,8 +402,12 @@ public function testWalletUnique(): void /** @var UserMulti $user */ $user = UserMultiFactory::new()->create(); - $user->createWallet(['name' => 'deposit']); - $user->createWallet(['name' => 'deposit']); + $user->createWallet([ + 'name' => 'deposit', + ]); + $user->createWallet([ + 'name' => 'deposit', + ]); } public function testGetWallet(): void @@ -416,25 +424,21 @@ public function testGetWallet(): void self::assertSame($secondWallet->getKey(), $firstWallet->getKey()); $uuid = app(UuidFactoryServiceInterface::class)->uuid4(); - $test2 = $user->wallets()->create([ - 'name' => 'Test2', - 'uuid' => $uuid, - ]); + $test2 = $user->wallets() + ->create([ + 'name' => 'Test2', + 'uuid' => $uuid, + ]) + ; self::assertNotNull($test2->refresh()); self::assertSame($uuid, $test2->uuid); - self::assertSame( - $test2->getKey(), - $user->getWallet('test2')->getKey() - ); + self::assertSame($test2->getKey(), $user->getWallet('test2')->getKey()); self::assertNotNull($user->wallets()->where('uuid', $uuid)->first()); // check default wallet - self::assertSame( - $user->balance, - $user->wallet->balance - ); + self::assertSame($user->balance, $user->wallet->balance); } public function testGetWalletOptimize(): void @@ -468,8 +472,12 @@ public function testPay(): void * @var Item $product */ $user = UserMultiFactory::new()->create(); - $a = $user->createWallet(['name' => 'a']); - $b = $user->createWallet(['name' => 'b']); + $a = $user->createWallet([ + 'name' => 'a', + ]); + $b = $user->createWallet([ + 'name' => 'b', + ]); $product = ItemFactory::new()->create([ 'quantity' => 1, @@ -530,7 +538,9 @@ public function testUserCashier(): void self::assertSame($transaction->amountInt, 100); self::assertSame($default->balanceInt, 100); - $newWallet = $user->createWallet(['name' => 'New Wallet']); + $newWallet = $user->createWallet([ + 'name' => 'New Wallet', + ]); $transfer = $default->transfer($newWallet, 100); self::assertSame($default->balanceInt, 0); @@ -554,7 +564,11 @@ public function testDecimalPlaces(): void $user = UserMultiFactory::new()->create(); self::assertNull($user->getWallet($slug)); - $wallet = $user->createWallet(['name' => 'Simple', 'slug' => $slug, 'decimal_places' => 6]); + $wallet = $user->createWallet([ + 'name' => 'Simple', + 'slug' => $slug, + 'decimal_places' => 6, + ]); self::assertNotNull($wallet); self::assertNotNull($user->wallet); self::assertSame($user->wallet->id, $wallet->id); @@ -571,7 +585,9 @@ public function testMultiWalletTransactionState(): void /** @var Wallet[] $wallets */ $wallets = []; foreach (range(1, 10) as $item) { - $wallets[] = $user->createWallet(['name' => 'index'.$item]); + $wallets[] = $user->createWallet([ + 'name' => 'index'.$item, + ]); } self::assertCount(10, $wallets); diff --git a/tests/Units/Domain/ProductTest.php b/tests/Units/Domain/ProductTest.php index 88145b322..e87f55f2a 100644 --- a/tests/Units/Domain/ProductTest.php +++ b/tests/Units/Domain/ProductTest.php @@ -21,7 +21,7 @@ /** * @internal */ -class ProductTest extends TestCase +final class ProductTest extends TestCase { public function testPay(): void { @@ -279,7 +279,9 @@ public function testProductMultiWallet(): void $buyer->deposit($product->getAmountProduct($buyer)); self::assertSame((string) $product->getAmountProduct($buyer), $buyer->balance); - $product->createWallet(['name' => 'testing']); + $product->createWallet([ + 'name' => 'testing', + ]); app(DatabaseServiceInterface::class)->transaction(function () use ($product, $buyer) { $transfer = $buyer->pay($product); $product->transfer($product->getWallet('testing'), $transfer->deposit->amount, $transfer->toArray()); diff --git a/tests/Units/Domain/StateTest.php b/tests/Units/Domain/StateTest.php index 16f9bf520..5ae7aa63c 100644 --- a/tests/Units/Domain/StateTest.php +++ b/tests/Units/Domain/StateTest.php @@ -16,7 +16,7 @@ /** * @internal */ -class StateTest extends TestCase +final class StateTest extends TestCase { /** * @see https://github.com/bavix/laravel-wallet/issues/49 @@ -34,14 +34,14 @@ public function testForceUpdate(): void self::assertSame(0, (int) app(RegulatorServiceInterface::class)->diff($wallet)); Wallet::whereKey($buyer->wallet->getKey()) - ->update(['balance' => 10]) + ->update([ + 'balance' => 10, + ]) ; /** - * Create a state when the cache is empty. - * For example, something went wrong and your database has incorrect data. - * Unfortunately, the library will work with what is. - * But there is an opportunity to recount the balance. + * Create a state when the cache is empty. For example, something went wrong and your database has incorrect + * data. Unfortunately, the library will work with what is. But there is an opportunity to recount the balance. * * Here is an example: */ diff --git a/tests/Units/Domain/TaxTest.php b/tests/Units/Domain/TaxTest.php index 979ca7d4d..dafecc739 100644 --- a/tests/Units/Domain/TaxTest.php +++ b/tests/Units/Domain/TaxTest.php @@ -16,7 +16,7 @@ /** * @internal */ -class TaxTest extends TestCase +final class TaxTest extends TestCase { public function testPay(): void { diff --git a/tests/Units/Domain/TransactionsFilterTest.php b/tests/Units/Domain/TransactionsFilterTest.php index 3e7a5347f..3a77d8804 100644 --- a/tests/Units/Domain/TransactionsFilterTest.php +++ b/tests/Units/Domain/TransactionsFilterTest.php @@ -12,7 +12,7 @@ /** * @internal */ -class TransactionsFilterTest extends TestCase +final class TransactionsFilterTest extends TestCase { public function testMetaAccount(): void { @@ -21,16 +21,34 @@ public function testMetaAccount(): void self::assertFalse($buyer->relationLoaded('wallet')); $buyer->deposit(1000); // without meta - $buyer->withdraw(100, ['account' => 'customers']); - $buyer->withdraw(150, ['account' => 'expenses']); - $buyer->deposit(500, ['account' => 'vendors']); + $buyer->withdraw(100, [ + 'account' => 'customers', + ]); + $buyer->withdraw(150, [ + 'account' => 'expenses', + ]); + $buyer->deposit(500, [ + 'account' => 'vendors', + ]); self::assertSame(4, $buyer->transactions()->count()); - $nullable = $buyer->transactions()->whereNull('meta')->count(); - $customers = $buyer->transactions()->where('meta->account', 'customers')->count(); - $expenses = $buyer->transactions()->where('meta->account', 'expenses')->count(); - $vendors = $buyer->transactions()->where('meta->account', 'vendors')->count(); + $nullable = $buyer->transactions() + ->whereNull('meta') + ->count() + ; + $customers = $buyer->transactions() + ->where('meta->account', 'customers') + ->count() + ; + $expenses = $buyer->transactions() + ->where('meta->account', 'expenses') + ->count() + ; + $vendors = $buyer->transactions() + ->where('meta->account', 'vendors') + ->count() + ; self::assertSame(1, $nullable); self::assertSame(1, $customers); diff --git a/tests/Units/Domain/WalletExtensionTest.php b/tests/Units/Domain/WalletExtensionTest.php index f7b7fc79b..53b8748fd 100644 --- a/tests/Units/Domain/WalletExtensionTest.php +++ b/tests/Units/Domain/WalletExtensionTest.php @@ -15,7 +15,7 @@ /** * @internal */ -class WalletExtensionTest extends TestCase +final class WalletExtensionTest extends TestCase { protected function setUp(): void { @@ -28,7 +28,9 @@ public function testCustomAttribute(): void /** @var Buyer $buyer */ $buyer = BuyerFactory::new()->create(); self::assertFalse($buyer->relationLoaded('wallet')); - $transaction = $buyer->deposit(1000, ['bank_method' => 'VietComBank']); + $transaction = $buyer->deposit(1000, [ + 'bank_method' => 'VietComBank', + ]); self::assertTrue($transaction->getKey() > 0); self::assertSame($transaction->amountInt, $buyer->balanceInt); @@ -46,7 +48,9 @@ public function testTransactionMoneyAttribute(): void */ $buyer = BuyerFactory::new()->create(); self::assertFalse($buyer->relationLoaded('wallet')); - $transaction = $buyer->deposit(1000, ['currency' => 'EUR']); + $transaction = $buyer->deposit(1000, [ + 'currency' => 'EUR', + ]); self::assertTrue($transaction->getKey() > 0); self::assertSame($transaction->amountInt, $buyer->balanceInt); diff --git a/tests/Units/Domain/WalletFloatTest.php b/tests/Units/Domain/WalletFloatTest.php index fd97dd366..4999b3afb 100644 --- a/tests/Units/Domain/WalletFloatTest.php +++ b/tests/Units/Domain/WalletFloatTest.php @@ -17,7 +17,7 @@ /** * @internal */ -class WalletFloatTest extends TestCase +final class WalletFloatTest extends TestCase { public function testDeposit(): void { diff --git a/tests/Units/Domain/WalletTest.php b/tests/Units/Domain/WalletTest.php index 2e86d5083..63c4ec708 100644 --- a/tests/Units/Domain/WalletTest.php +++ b/tests/Units/Domain/WalletTest.php @@ -22,7 +22,7 @@ /** * @internal */ -class WalletTest extends TestCase +final class WalletTest extends TestCase { public function testDeposit(): void { @@ -44,19 +44,13 @@ public function testDeposit(): void $user->withdraw($user->balanceInt); self::assertSame(0, $user->balanceInt); - self::assertSame( - 3, - $user->transactions() - ->where(['type' => Transaction::TYPE_DEPOSIT]) - ->count() - ); + self::assertSame(3, $user->transactions()->where([ + 'type' => Transaction::TYPE_DEPOSIT, + ])->count()); - self::assertSame( - 1, - $user->transactions() - ->where(['type' => Transaction::TYPE_WITHDRAW]) - ->count() - ); + self::assertSame(1, $user->transactions()->where([ + 'type' => Transaction::TYPE_WITHDRAW, + ])->count()); self::assertSame(4, $user->transactions()->count()); } @@ -103,21 +97,9 @@ public function testFindUserByExistsWallet(): void } } - self::assertCount( - 1, - User::query() - ->has('wallet') - ->whereIn('id', $ids) - ->get() - ); - - self::assertCount( - 9, - User::query() - ->has('wallet', '<') - ->whereIn('id', $ids) - ->get() - ); + self::assertCount(1, User::query()->has('wallet')->whereIn('id', $ids)->get()); + + self::assertCount(9, User::query()->has('wallet', '<')->whereIn('id', $ids)->get()); } public function testWithdraw(): void @@ -284,7 +266,11 @@ public function testRecalculate(): void $user->deposit(100, null, false); self::assertSame(0, $user->balanceInt); - $user->transactions()->update(['confirmed' => true]); + $user->transactions() + ->update([ + 'confirmed' => true, + ]) + ; self::assertSame(0, $user->balanceInt); $user->wallet->refreshBalance(); diff --git a/tests/Units/Service/BookkeeperTest.php b/tests/Units/Service/BookkeeperTest.php index f1162003a..47ca88372 100644 --- a/tests/Units/Service/BookkeeperTest.php +++ b/tests/Units/Service/BookkeeperTest.php @@ -12,7 +12,7 @@ /** * @internal */ -class BookkeeperTest extends TestCase +final class BookkeeperTest extends TestCase { public function testSync(): void { diff --git a/tests/Units/Service/DispatcherTest.php b/tests/Units/Service/DispatcherTest.php index 9d8784d85..1245338aa 100644 --- a/tests/Units/Service/DispatcherTest.php +++ b/tests/Units/Service/DispatcherTest.php @@ -13,7 +13,7 @@ /** * @internal */ -class DispatcherTest extends TestCase +final class DispatcherTest extends TestCase { public function testUnknownEventException(): void { diff --git a/tests/Units/Service/LockServiceTest.php b/tests/Units/Service/LockServiceTest.php index 1fc363944..201ed24ed 100644 --- a/tests/Units/Service/LockServiceTest.php +++ b/tests/Units/Service/LockServiceTest.php @@ -10,7 +10,7 @@ /** * @internal */ -class LockServiceTest extends TestCase +final class LockServiceTest extends TestCase { public function testBlock(): void { diff --git a/tests/Units/Service/MathTest.php b/tests/Units/Service/MathTest.php index e273bdea3..14f8b7deb 100644 --- a/tests/Units/Service/MathTest.php +++ b/tests/Units/Service/MathTest.php @@ -12,7 +12,7 @@ /** * @internal */ -class MathTest extends TestCase +final class MathTest extends TestCase { /** * @dataProvider invalidProvider @@ -230,29 +230,14 @@ public function testCeil(): void // positive // int - self::assertSame( - '35458', - $provider->ceil(35458) - ); + self::assertSame('35458', $provider->ceil(35458)); // float self::assertSame('35458', $provider->ceil('35458.00000000')); - self::assertSame( - '35459', - $provider->ceil(35458.0000001) - ); - self::assertSame( - '35459', - $provider->ceil(35458.4) - ); - self::assertSame( - '35459', - $provider->ceil(35458.5) - ); - self::assertSame( - '35459', - $provider->ceil(35458.6) - ); + self::assertSame('35459', $provider->ceil(35458.0000001)); + self::assertSame('35459', $provider->ceil(35458.4)); + self::assertSame('35459', $provider->ceil(35458.5)); + self::assertSame('35459', $provider->ceil(35458.6)); // string self::assertSame( @@ -262,28 +247,13 @@ public function testCeil(): void // negative // int - self::assertSame( - '-35458', - $provider->ceil(-35458) - ); + self::assertSame('-35458', $provider->ceil(-35458)); // float - self::assertSame( - '-35458', - $provider->ceil(-35458.0000001) - ); - self::assertSame( - '-35458', - $provider->ceil(-35458.4) - ); - self::assertSame( - '-35458', - $provider->ceil(-35458.5) - ); - self::assertSame( - '-35458', - $provider->ceil(-35458.6) - ); + self::assertSame('-35458', $provider->ceil(-35458.0000001)); + self::assertSame('-35458', $provider->ceil(-35458.4)); + self::assertSame('-35458', $provider->ceil(-35458.5)); + self::assertSame('-35458', $provider->ceil(-35458.6)); // string self::assertSame( @@ -299,29 +269,14 @@ public function testFloor(): void // positive // int - self::assertSame( - '35458', - $provider->floor(35458) - ); + self::assertSame('35458', $provider->floor(35458)); // float self::assertSame('35458', $provider->floor('35458.00000000')); - self::assertSame( - '35458', - $provider->floor(35458.0000001) - ); - self::assertSame( - '35458', - $provider->floor(35458.4) - ); - self::assertSame( - '35458', - $provider->floor(35458.5) - ); - self::assertSame( - '35458', - $provider->floor(35458.6) - ); + self::assertSame('35458', $provider->floor(35458.0000001)); + self::assertSame('35458', $provider->floor(35458.4)); + self::assertSame('35458', $provider->floor(35458.5)); + self::assertSame('35458', $provider->floor(35458.6)); // string self::assertSame( @@ -331,28 +286,13 @@ public function testFloor(): void // negative // int - self::assertSame( - '-35458', - $provider->floor(-35458) - ); + self::assertSame('-35458', $provider->floor(-35458)); // float - self::assertSame( - '-35459', - $provider->floor(-35458.0000001) - ); - self::assertSame( - '-35459', - $provider->floor(-35458.4) - ); - self::assertSame( - '-35459', - $provider->floor(-35458.5) - ); - self::assertSame( - '-35459', - $provider->floor(-35458.6) - ); + self::assertSame('-35459', $provider->floor(-35458.0000001)); + self::assertSame('-35459', $provider->floor(-35458.4)); + self::assertSame('-35459', $provider->floor(-35458.5)); + self::assertSame('-35459', $provider->floor(-35458.6)); // string self::assertSame( @@ -368,29 +308,14 @@ public function testRound(): void // positive // int - self::assertSame( - '35458', - $provider->round(35458) - ); + self::assertSame('35458', $provider->round(35458)); // float self::assertSame('35458', $provider->round('35458.00000000')); - self::assertSame( - '35458', - $provider->round(35458.0000001) - ); - self::assertSame( - '35458', - $provider->round(35458.4) - ); - self::assertSame( - '35459', - $provider->round(35458.5) - ); - self::assertSame( - '35459', - $provider->round(35458.6) - ); + self::assertSame('35458', $provider->round(35458.0000001)); + self::assertSame('35458', $provider->round(35458.4)); + self::assertSame('35459', $provider->round(35458.5)); + self::assertSame('35459', $provider->round(35458.6)); // string self::assertSame( @@ -400,28 +325,13 @@ public function testRound(): void // negative // int - self::assertSame( - '-35458', - $provider->round(-35458) - ); + self::assertSame('-35458', $provider->round(-35458)); // float - self::assertSame( - '-35458', - $provider->round(-35458.0000001) - ); - self::assertSame( - '-35458', - $provider->round(-35458.4) - ); - self::assertSame( - '-35459', - $provider->round(-35458.5) - ); - self::assertSame( - '-35459', - $provider->round(-35458.6) - ); + self::assertSame('-35458', $provider->round(-35458.0000001)); + self::assertSame('-35458', $provider->round(-35458.4)); + self::assertSame('-35459', $provider->round(-35458.5)); + self::assertSame('-35459', $provider->round(-35458.6)); // string self::assertSame( @@ -432,11 +342,6 @@ public function testRound(): void public function invalidProvider(): array { - return [ - ['.'], - ['hello'], - ['--121'], - ['---121'], - ]; + return [['.'], ['hello'], ['--121'], ['---121']]; } } diff --git a/tests/Units/Service/SingletonTest.php b/tests/Units/Service/SingletonTest.php index 40710d5d2..f71b0652c 100644 --- a/tests/Units/Service/SingletonTest.php +++ b/tests/Units/Service/SingletonTest.php @@ -16,7 +16,7 @@ /** * @internal */ -class SingletonTest extends TestCase +final class SingletonTest extends TestCase { public function testCart(): void { @@ -50,7 +50,10 @@ public function testCommonService(): void public function testDatabaseService(): void { - self::assertSame($this->getRefId(DatabaseServiceInterface::class), $this->getRefId(DatabaseServiceInterface::class)); + self::assertSame( + $this->getRefId(DatabaseServiceInterface::class), + $this->getRefId(DatabaseServiceInterface::class) + ); } protected function getRefId(string $object): string diff --git a/tests/Units/Service/StorageTest.php b/tests/Units/Service/StorageTest.php index f6d85231e..3607ca9f1 100644 --- a/tests/Units/Service/StorageTest.php +++ b/tests/Units/Service/StorageTest.php @@ -12,7 +12,7 @@ /** * @internal */ -class StorageTest extends TestCase +final class StorageTest extends TestCase { public function testFlush(): void { diff --git a/tests/Units/Service/WalletTest.php b/tests/Units/Service/WalletTest.php index 6a49b4130..30f3cd201 100644 --- a/tests/Units/Service/WalletTest.php +++ b/tests/Units/Service/WalletTest.php @@ -15,7 +15,7 @@ /** * @internal */ -class WalletTest extends TestCase +final class WalletTest extends TestCase { public function testFindBy(): void { diff --git a/tests/migrations/2019_09_19_191432_alter_column_transaction_table.php b/tests/migrations/2019_09_19_191432_alter_column_transaction_table.php index c0a17f05d..e28be6952 100644 --- a/tests/migrations/2019_09_19_191432_alter_column_transaction_table.php +++ b/tests/migrations/2019_09_19_191432_alter_column_transaction_table.php @@ -15,7 +15,9 @@ class AlterColumnTransactionTable extends Migration public function up() { Schema::table((new Transaction())->getTable(), function (Blueprint $table) { - $table->string('bank_method')->nullable(); + $table->string('bank_method') + ->nullable() + ; }); } diff --git a/tests/migrations/2022_01_26_185311_create_managers_table.php b/tests/migrations/2022_01_26_185311_create_managers_table.php index 37344d1a5..b684be071 100644 --- a/tests/migrations/2022_01_26_185311_create_managers_table.php +++ b/tests/migrations/2022_01_26_185311_create_managers_table.php @@ -11,7 +11,9 @@ final class CreateManagersTable extends Migration public function up(): void { Schema::create('managers', static function (Blueprint $table) { - $table->uuid('id')->primary(); + $table->uuid('id') + ->primary() + ; $table->string('name'); $table->string('email'); $table->timestamps();