diff --git a/.github/workflows/autofix.yaml b/.github/workflows/autofix.yaml new file mode 100644 index 000000000..04170977c --- /dev/null +++ b/.github/workflows/autofix.yaml @@ -0,0 +1,89 @@ +name: fixer + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + autofix: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath + coverage: pcov + env: + runner: self-hosted + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run rector-fix + run: composer rector-fix + + - name: Run ecs-fix + run: composer ecs-fix + + - name: Run rector + run: composer rector + + - name: Run ecs + run: composer ecs + + - name: Run parabench + run: composer parabench + + - name: "Check if build has changed" + if: success() + id: has-changes + run: | + echo "stdout<> $GITHUB_OUTPUT + echo "$(git diff --stat)" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + - name: Import GPG key + if: ${{ steps.has-changes.outputs.stdout }} + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_BOT }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + fingerprint: ${{ secrets.GPG_FINGERPRINT }} + git_config_global: true + git_user_signingkey: true + git_commit_gpgsign: true + git_committer_name: Github bot + git_committer_email: bot@babichev.net + + - name: "Commit files" + if: ${{ steps.has-changes.outputs.stdout }} + env: + GH_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + gh pr checkout ${{ github.event.pull_request.number }} + git commit -S -m "autofix" -a + + - name: "Push changes" + if: ${{ steps.has-changes.outputs.stdout }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: git push -u origin HEAD diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml deleted file mode 100644 index 217d24b4a..000000000 --- a/.github/workflows/code-style.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: code-style - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - ecs: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: bcmath - env: - runner: self-hosted - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run ecs - run: composer ecs diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml deleted file mode 100644 index d164fcf1d..000000000 --- a/.github/workflows/rector.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: rector - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - rector: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: bcmath - env: - runner: self-hosted - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run rector - run: composer rector diff --git a/database/2018_11_06_222923_create_transactions_table.php b/database/2018_11_06_222923_create_transactions_table.php index 87e891365..107d835a6 100644 --- a/database/2018_11_06_222923_create_transactions_table.php +++ b/database/2018_11_06_222923_create_transactions_table.php @@ -7,7 +7,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create($this->table(), static function (Blueprint $table) { @@ -18,11 +19,9 @@ public function up(): void $table->decimal('amount', 64, 0); $table->boolean('confirmed'); $table->json('meta') - ->nullable() - ; + ->nullable(); $table->uuid('uuid') - ->unique() - ; + ->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 f003d941c..ea5be2f68 100644 --- a/database/2018_11_07_192923_create_transfers_table.php +++ b/database/2018_11_07_192923_create_transfers_table.php @@ -8,7 +8,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create($this->table(), function (Blueprint $table) { @@ -17,41 +18,34 @@ public function up(): void $table->morphs('to'); $table ->enum('status', ['exchange', 'transfer', 'paid', 'refund', 'gift']) - ->default('transfer') - ; + ->default('transfer'); $table ->enum('status_last', ['exchange', 'transfer', 'paid', 'refund', 'gift']) - ->nullable() - ; + ->nullable(); $table->unsignedBigInteger('deposit_id'); $table->unsignedBigInteger('withdraw_id'); $table->decimal('discount', 64, 0) - ->default(0) - ; + ->default(0); $table->decimal('fee', 64, 0) - ->default(0) - ; + ->default(0); $table->uuid('uuid') - ->unique() - ; + ->unique(); $table->timestamps(); $table->foreign('deposit_id') ->references('id') ->on($this->transactionTable()) - ->onDelete('cascade') - ; + ->onDelete('cascade'); $table->foreign('withdraw_id') ->references('id') ->on($this->transactionTable()) - ->onDelete('cascade') - ; + ->onDelete('cascade'); }); } diff --git a/database/2018_11_15_124230_create_wallets_table.php b/database/2018_11_15_124230_create_wallets_table.php index 432d2e595..342fe4815 100644 --- a/database/2018_11_15_124230_create_wallets_table.php +++ b/database/2018_11_15_124230_create_wallets_table.php @@ -8,7 +8,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create($this->table(), static function (Blueprint $table) { @@ -16,23 +17,17 @@ public function up(): void $table->morphs('holder'); $table->string('name'); $table->string('slug') - ->index() - ; + ->index(); $table->uuid('uuid') - ->unique() - ; + ->unique(); $table->string('description') - ->nullable() - ; + ->nullable(); $table->json('meta') - ->nullable() - ; + ->nullable(); $table->decimal('balance', 64, 0) - ->default(0) - ; + ->default(0); $table->unsignedSmallInteger('decimal_places') - ->default(2) - ; + ->default(2); $table->timestamps(); $table->unique(['holder_type', 'holder_id', 'slug']); @@ -42,8 +37,7 @@ public function up(): void $table->foreign('wallet_id') ->references('id') ->on($this->table()) - ->onDelete('cascade') - ; + ->onDelete('cascade'); }); } diff --git a/database/2021_11_02_202021_update_wallets_uuid_table.php b/database/2021_11_02_202021_update_wallets_uuid_table.php index 3125848c5..55c752b24 100644 --- a/database/2021_11_02_202021_update_wallets_uuid_table.php +++ b/database/2021_11_02_202021_update_wallets_uuid_table.php @@ -9,7 +9,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { if (Schema::hasColumn($this->table(), 'uuid')) { @@ -21,8 +22,7 @@ public function up(): void $table->uuid('uuid') ->after('slug') ->nullable() - ->unique() - ; + ->unique(); }); Wallet::query()->chunk(10000, static function (Collection $wallets) { @@ -34,8 +34,7 @@ public function up(): void Schema::table($this->table(), static function (Blueprint $table) { $table->uuid('uuid') - ->change() - ; + ->change(); }); } diff --git a/database/2023_12_30_113122_extra_columns_removed.php b/database/2023_12_30_113122_extra_columns_removed.php index 2e126aac8..8e22a2452 100644 --- a/database/2023_12_30_113122_extra_columns_removed.php +++ b/database/2023_12_30_113122_extra_columns_removed.php @@ -7,7 +7,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::table($this->table(), function (Blueprint $table) { @@ -25,11 +26,9 @@ public function down(): void { Schema::table($this->table(), static function (Blueprint $table) { $table->string('from_type') - ->after('from_id') - ; + ->after('from_id'); $table->string('to_type') - ->after('to_id') - ; + ->after('to_id'); }); } diff --git a/database/2023_12_30_204610_soft_delete.php b/database/2023_12_30_204610_soft_delete.php index 3b84c9e58..84f4f2b88 100644 --- a/database/2023_12_30_204610_soft_delete.php +++ b/database/2023_12_30_204610_soft_delete.php @@ -9,7 +9,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::table((new Wallet())->getTable(), static function (Blueprint $table) { diff --git a/database/2024_01_24_185401_add_extra_column_in_transfer.php b/database/2024_01_24_185401_add_extra_column_in_transfer.php index 9a9f7d6ac..07a088a13 100644 --- a/database/2024_01_24_185401_add_extra_column_in_transfer.php +++ b/database/2024_01_24_185401_add_extra_column_in_transfer.php @@ -7,14 +7,14 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::table($this->table(), static function (Blueprint $table) { $table->json('extra') ->nullable() - ->after('fee') - ; + ->after('fee'); }); } diff --git a/ecs.php b/ecs.php index 406bcf765..fcf4a7dce 100644 --- a/ecs.php +++ b/ecs.php @@ -22,11 +22,13 @@ $config->sets([ SetList::CLEAN_CODE, SetList::SYMPLIFY, + SetList::ARRAY, SetList::COMMON, SetList::PSR_12, SetList::CONTROL_STRUCTURES, SetList::NAMESPACES, SetList::STRICT, SetList::PHPUNIT, + SetList::LARAVEL, ]); }; diff --git a/rector.php b/rector.php index 945b1ac02..e10f29768 100644 --- a/rector.php +++ b/rector.php @@ -16,6 +16,10 @@ // Define what rule sets will be applied $config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES); $config->import(PHPUnitSetList::PHPUNIT_100); + $config->import(SetList::STRICT_BOOLEANS); + $config->import(SetList::PRIVATIZATION); + $config->import(SetList::EARLY_RETURN); + $config->import(SetList::INSTANCEOF); $config->import(SetList::CODE_QUALITY); $config->import(SetList::DEAD_CODE); $config->import(SetList::PHP_82); diff --git a/src/External/Api/TransactionQueryHandlerInterface.php b/src/External/Api/TransactionQueryHandlerInterface.php index 7ba3ac0b3..1bfffb53a 100644 --- a/src/External/Api/TransactionQueryHandlerInterface.php +++ b/src/External/Api/TransactionQueryHandlerInterface.php @@ -18,7 +18,6 @@ interface TransactionQueryHandlerInterface * and check the correctness of the balance manually. * * @param non-empty-array $objects - * * @return non-empty-array * * @throws ExceptionInterface diff --git a/src/External/Api/TransferQueryHandlerInterface.php b/src/External/Api/TransferQueryHandlerInterface.php index 095c4c78f..10cba0963 100644 --- a/src/External/Api/TransferQueryHandlerInterface.php +++ b/src/External/Api/TransferQueryHandlerInterface.php @@ -18,7 +18,6 @@ interface TransferQueryHandlerInterface * and check the correctness of the balance manually. * * @param non-empty-array $objects - * * @return non-empty-array * * @throws ExceptionInterface diff --git a/src/Interfaces/Customer.php b/src/Interfaces/Customer.php index 228ef353b..cf56b3286 100644 --- a/src/Interfaces/Customer.php +++ b/src/Interfaces/Customer.php @@ -94,6 +94,8 @@ public function refundGift(ProductInterface $product, bool $force = false): bool public function forceRefundGift(ProductInterface $product): bool; /** + * @return non-empty-array + * * @throws ProductEnded * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -101,8 +103,6 @@ public function forceRefundGift(ProductInterface $product): bool; * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function payFreeCart(CartInterface $cart): array; @@ -112,6 +112,8 @@ public function payFreeCart(CartInterface $cart): array; public function safePayCart(CartInterface $cart, bool $force = false): array; /** + * @return non-empty-array + * * @throws ProductEnded * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -119,19 +121,17 @@ public function safePayCart(CartInterface $cart, bool $force = false): array; * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function payCart(CartInterface $cart, bool $force = false): array; /** + * @return non-empty-array + * * @throws ProductEnded * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function forcePayCart(CartInterface $cart): array; diff --git a/src/Internal/Assembler/TransferDtoAssembler.php b/src/Internal/Assembler/TransferDtoAssembler.php index 93605bf64..327311744 100644 --- a/src/Internal/Assembler/TransferDtoAssembler.php +++ b/src/Internal/Assembler/TransferDtoAssembler.php @@ -18,7 +18,9 @@ public function __construct( ) { } - /** @param array|null $extra */ + /** + * @param array|null $extra + */ public function create( int $depositId, int $withdrawId, diff --git a/src/Internal/Assembler/TransferDtoAssemblerInterface.php b/src/Internal/Assembler/TransferDtoAssemblerInterface.php index 4300f0c2d..8da6079f6 100644 --- a/src/Internal/Assembler/TransferDtoAssemblerInterface.php +++ b/src/Internal/Assembler/TransferDtoAssemblerInterface.php @@ -9,7 +9,9 @@ interface TransferDtoAssemblerInterface { - /** @param array|null $extra */ + /** + * @param array|null $extra + */ public function create( int $depositId, int $withdrawId, diff --git a/src/Internal/Assembler/TransferLazyDtoAssembler.php b/src/Internal/Assembler/TransferLazyDtoAssembler.php index f2ed0cf46..efb67b3c0 100644 --- a/src/Internal/Assembler/TransferLazyDtoAssembler.php +++ b/src/Internal/Assembler/TransferLazyDtoAssembler.php @@ -11,7 +11,9 @@ final class TransferLazyDtoAssembler implements TransferLazyDtoAssemblerInterface { - /** @param array|null $extra */ + /** + * @param array|null $extra + */ public function create( Wallet $fromWallet, Wallet $toWallet, diff --git a/src/Internal/Assembler/TransferLazyDtoAssemblerInterface.php b/src/Internal/Assembler/TransferLazyDtoAssemblerInterface.php index 08d348dc1..9bb99dd86 100644 --- a/src/Internal/Assembler/TransferLazyDtoAssemblerInterface.php +++ b/src/Internal/Assembler/TransferLazyDtoAssemblerInterface.php @@ -10,7 +10,9 @@ interface TransferLazyDtoAssemblerInterface { - /** @param array|null $extra */ + /** + * @param array|null $extra + */ public function create( Wallet $fromWallet, Wallet $toWallet, diff --git a/src/Internal/Decorator/StorageServiceLockDecorator.php b/src/Internal/Decorator/StorageServiceLockDecorator.php index 1e4c449c3..8c97eddd7 100644 --- a/src/Internal/Decorator/StorageServiceLockDecorator.php +++ b/src/Internal/Decorator/StorageServiceLockDecorator.php @@ -60,6 +60,7 @@ public function multiGet(array $uuids): array $item = $this->stateService->get($uuid); if ($item === null) { $missingKeys[] = $uuid; + continue; } diff --git a/src/Internal/Dto/TransferDto.php b/src/Internal/Dto/TransferDto.php index cda55fe4d..f548cdc3a 100644 --- a/src/Internal/Dto/TransferDto.php +++ b/src/Internal/Dto/TransferDto.php @@ -9,7 +9,9 @@ /** @immutable */ final readonly class TransferDto implements TransferDtoInterface { - /** @param array|null $extra */ + /** + * @param array|null $extra + */ public function __construct( private string $uuid, private int $depositId, diff --git a/src/Internal/Dto/TransferDtoInterface.php b/src/Internal/Dto/TransferDtoInterface.php index 21c4364dc..4aab8c16e 100644 --- a/src/Internal/Dto/TransferDtoInterface.php +++ b/src/Internal/Dto/TransferDtoInterface.php @@ -24,7 +24,9 @@ public function getDiscount(): int; public function getFee(): string; - /** @return array|null */ + /** + * @return array|null + */ public function getExtra(): ?array; public function getCreatedAt(): DateTimeImmutable; diff --git a/src/Internal/Dto/TransferLazyDtoInterface.php b/src/Internal/Dto/TransferLazyDtoInterface.php index e02e23aaa..21bd70196 100644 --- a/src/Internal/Dto/TransferLazyDtoInterface.php +++ b/src/Internal/Dto/TransferLazyDtoInterface.php @@ -24,6 +24,8 @@ public function getStatus(): string; public function getUuid(): ?string; - /** @return array|null */ + /** + * @return array|null + */ public function getExtra(): ?array; } diff --git a/src/Internal/Query/TransactionQuery.php b/src/Internal/Query/TransactionQuery.php index 51ab135fc..68c4dc521 100644 --- a/src/Internal/Query/TransactionQuery.php +++ b/src/Internal/Query/TransactionQuery.php @@ -6,6 +6,7 @@ /** * @immutable + * * @internal */ final readonly class TransactionQuery implements TransactionQueryInterface diff --git a/src/Internal/Query/TransferQuery.php b/src/Internal/Query/TransferQuery.php index 3486a266e..2b92283aa 100644 --- a/src/Internal/Query/TransferQuery.php +++ b/src/Internal/Query/TransferQuery.php @@ -6,6 +6,7 @@ /** * @immutable + * * @internal */ final readonly class TransferQuery implements TransferQueryInterface diff --git a/src/Internal/Repository/TransactionRepository.php b/src/Internal/Repository/TransactionRepository.php index 185fd415f..36946e900 100644 --- a/src/Internal/Repository/TransactionRepository.php +++ b/src/Internal/Repository/TransactionRepository.php @@ -33,8 +33,7 @@ public function insert(array $objects): void } $this->transaction->newQuery() - ->insert($values) - ; + ->insert($values); } public function insertOne(TransactionDtoInterface $dto): Transaction @@ -54,7 +53,6 @@ public function findBy(TransactionQueryInterface $query): array return $this->transaction->newQuery() ->whereIn('uuid', $query->getUuids()) ->get() - ->all() - ; + ->all(); } } diff --git a/src/Internal/Repository/TransferRepository.php b/src/Internal/Repository/TransferRepository.php index 19734db4a..4c946e5fb 100644 --- a/src/Internal/Repository/TransferRepository.php +++ b/src/Internal/Repository/TransferRepository.php @@ -33,8 +33,7 @@ public function insert(array $objects): void } $this->transfer->newQuery() - ->insert($values) - ; + ->insert($values); } public function insertOne(TransferDtoInterface $dto): Transfer @@ -54,8 +53,7 @@ public function findBy(TransferQueryInterface $query): array return $this->transfer->newQuery() ->whereIn('uuid', $query->getUuids()) ->get() - ->all() - ; + ->all(); } /** @@ -71,7 +69,6 @@ public function updateStatusByIds(string $status, array $ids): int ->update([ 'status_last' => $connection->raw('status'), 'status' => $status, - ]) - ; + ]); } } diff --git a/src/Internal/Repository/WalletRepository.php b/src/Internal/Repository/WalletRepository.php index 893889ef8..bc512df13 100644 --- a/src/Internal/Repository/WalletRepository.php +++ b/src/Internal/Repository/WalletRepository.php @@ -40,11 +40,11 @@ public function updateBalances(array $data): int $cases = []; foreach ($data as $walletId => $balance) { - $cases[] = 'WHEN id = ' . $walletId . ' THEN ' . $balance; + $cases[] = 'WHEN id = '.$walletId.' THEN '.$balance; } $buildQuery = $this->wallet->getConnection() - ->raw('CASE ' . implode(' ', $cases) . ' END'); + ->raw('CASE '.implode(' ', $cases).' END'); return $this->wallet->newQuery() ->whereIn('id', array_keys($data)) @@ -114,7 +114,6 @@ public function getBySlug(string $holderType, int|string $holderId, string $slug /** * @param array $holderIds - * * @return Wallet[] */ public function findDefaultAll(string $holderType, array $holderIds): array @@ -124,8 +123,7 @@ public function findDefaultAll(string $holderType, array $holderIds): array ->where('holder_type', $holderType) ->whereIn('holder_id', $holderIds) ->get() - ->all() - ; + ->all(); } /** @@ -138,8 +136,7 @@ private function getBy(array $attributes): Wallet try { $wallet = $this->wallet->newQuery() ->where($attributes) - ->firstOrFail() - ; + ->firstOrFail(); assert($wallet instanceof Wallet); return $wallet; diff --git a/src/Internal/Repository/WalletRepositoryInterface.php b/src/Internal/Repository/WalletRepositoryInterface.php index ac04b960b..9b91480de 100644 --- a/src/Internal/Repository/WalletRepositoryInterface.php +++ b/src/Internal/Repository/WalletRepositoryInterface.php @@ -37,7 +37,6 @@ public function findBySlug(string $holderType, int|string $holderId, string $slu /** * @param array $holderIds - * * @return Wallet[] */ public function findDefaultAll(string $holderType, array $holderIds): array; diff --git a/src/Internal/Service/DatabaseService.php b/src/Internal/Service/DatabaseService.php index c64d591c7..c3f90e5ce 100644 --- a/src/Internal/Service/DatabaseService.php +++ b/src/Internal/Service/DatabaseService.php @@ -45,7 +45,7 @@ public function transaction(callable $callback): mixed throw $exception; } catch (Throwable $throwable) { throw new TransactionFailedException( - 'Transaction failed. Message: ' . $throwable->getMessage(), + 'Transaction failed. Message: '.$throwable->getMessage(), ExceptionInterface::TRANSACTION_FAILED, $throwable ); diff --git a/src/Internal/Service/DatabaseServiceInterface.php b/src/Internal/Service/DatabaseServiceInterface.php index b844366c9..f7288d6c2 100644 --- a/src/Internal/Service/DatabaseServiceInterface.php +++ b/src/Internal/Service/DatabaseServiceInterface.php @@ -12,6 +12,7 @@ interface DatabaseServiceInterface { /** * @template T + * * @param callable(): T $callback * @return T * diff --git a/src/Internal/Service/LockService.php b/src/Internal/Service/LockService.php index 0ce589741..96342ddbe 100644 --- a/src/Internal/Service/LockService.php +++ b/src/Internal/Service/LockService.php @@ -36,8 +36,8 @@ public function block(string $key, callable $callback): mixed } $lock = $this->getLockProvider() - ->lock(self::LOCK_KEY . $key, $this->seconds); - $this->lockedKeys->put(self::INNER_KEYS . $key, true, $this->seconds); + ->lock(self::LOCK_KEY.$key, $this->seconds); + $this->lockedKeys->put(self::INNER_KEYS.$key, true, $this->seconds); // let's release the lock after the transaction, the fight against the race if ($this->connectionService->get()->transactionLevel() > 0) { @@ -49,15 +49,15 @@ public function block(string $key, callable $callback): mixed try { return $lock->block($this->seconds, $callback); } finally { - $this->lockedKeys->delete(self::INNER_KEYS . $key); + $this->lockedKeys->delete(self::INNER_KEYS.$key); } } /** * @template T + * * @param string[] $keys * @param callable(): T $callback - * * @return T */ public function blocks(array $keys, callable $callback): mixed @@ -82,16 +82,16 @@ public function releases(array $keys): void } $lockProvider - ->lock(self::LOCK_KEY . $key, $this->seconds) + ->lock(self::LOCK_KEY.$key, $this->seconds) ->forceRelease(); - $this->lockedKeys->delete(self::INNER_KEYS . $key); + $this->lockedKeys->delete(self::INNER_KEYS.$key); } } public function isBlocked(string $key): bool { - return $this->lockedKeys->get(self::INNER_KEYS . $key) === true; + return $this->lockedKeys->get(self::INNER_KEYS.$key) === true; } private function getLockProvider(): LockProvider diff --git a/src/Internal/Service/LockServiceInterface.php b/src/Internal/Service/LockServiceInterface.php index 82f5eba31..543586497 100644 --- a/src/Internal/Service/LockServiceInterface.php +++ b/src/Internal/Service/LockServiceInterface.php @@ -8,17 +8,17 @@ interface LockServiceInterface { /** * @template T - * @param callable(): T $callback * + * @param callable(): T $callback * @return T */ public function block(string $key, callable $callback): mixed; /** * @template T + * * @param string[] $keys * @param callable(): T $callback - * * @return T */ public function blocks(array $keys, callable $callback): mixed; diff --git a/src/Internal/Service/MathService.php b/src/Internal/Service/MathService.php index 55680f139..008e89424 100644 --- a/src/Internal/Service/MathService.php +++ b/src/Internal/Service/MathService.php @@ -18,39 +18,34 @@ public function add(float|int|string $first, float|int|string $second, ?int $sca { return (string) BigDecimal::of($first) ->plus(BigDecimal::of($second)) - ->toScale($scale ?? $this->scale, RoundingMode::DOWN) - ; + ->toScale($scale ?? $this->scale, RoundingMode::DOWN); } public function sub(float|int|string $first, float|int|string $second, ?int $scale = null): string { return (string) BigDecimal::of($first) ->minus(BigDecimal::of($second)) - ->toScale($scale ?? $this->scale, RoundingMode::DOWN) - ; + ->toScale($scale ?? $this->scale, RoundingMode::DOWN); } public function div(float|int|string $first, float|int|string $second, ?int $scale = null): string { return (string) BigDecimal::of($first) - ->dividedBy(BigDecimal::of($second), $scale ?? $this->scale, RoundingMode::DOWN) - ; + ->dividedBy(BigDecimal::of($second), $scale ?? $this->scale, RoundingMode::DOWN); } public function mul(float|int|string $first, float|int|string $second, ?int $scale = null): string { return (string) BigDecimal::of($first) ->multipliedBy(BigDecimal::of($second)) - ->toScale($scale ?? $this->scale, RoundingMode::DOWN) - ; + ->toScale($scale ?? $this->scale, RoundingMode::DOWN); } public function pow(float|int|string $first, float|int|string $second, ?int $scale = null): string { return (string) BigDecimal::of($first) ->power((int) $second) - ->toScale($scale ?? $this->scale, RoundingMode::DOWN) - ; + ->toScale($scale ?? $this->scale, RoundingMode::DOWN); } public function powTen(float|int|string $number): string @@ -61,22 +56,19 @@ public function powTen(float|int|string $number): string public function ceil(float|int|string $number): string { return (string) BigDecimal::of($number) - ->dividedBy(BigDecimal::one(), 0, RoundingMode::CEILING) - ; + ->dividedBy(BigDecimal::one(), 0, RoundingMode::CEILING); } public function floor(float|int|string $number): string { return (string) BigDecimal::of($number) - ->dividedBy(BigDecimal::one(), 0, RoundingMode::FLOOR) - ; + ->dividedBy(BigDecimal::one(), 0, RoundingMode::FLOOR); } public function round(float|int|string $number, int $precision = 0): string { return (string) BigDecimal::of($number) - ->dividedBy(BigDecimal::one(), $precision, RoundingMode::HALF_UP) - ; + ->dividedBy(BigDecimal::one(), $precision, RoundingMode::HALF_UP); } public function abs(float|int|string $number): string diff --git a/src/Internal/Service/StateService.php b/src/Internal/Service/StateService.php index 43602466c..8fcd411da 100644 --- a/src/Internal/Service/StateService.php +++ b/src/Internal/Service/StateService.php @@ -47,13 +47,13 @@ public function multiFork(array $uuids, callable $value): void $forkId = $this->getForkId(); $values = [ - self::PREFIX_FORK_REF . $forkId => $value, - self::PREFIX_HASHMAP . $forkId => $uuids, + self::PREFIX_FORK_REF.$forkId => $value, + self::PREFIX_HASHMAP.$forkId => $uuids, ]; foreach ($uuids as $uuid) { - $values[self::PREFIX_STATE . $uuid] = null; - $values[self::PREFIX_FORK_ID . $uuid] = $forkId; + $values[self::PREFIX_STATE.$uuid] = null; + $values[self::PREFIX_FORK_ID.$uuid] = $forkId; } $this->store->setMultiple($values); @@ -61,18 +61,18 @@ public function multiFork(array $uuids, callable $value): void public function get(string $uuid): ?string { - $value = $this->store->get(self::PREFIX_STATE . $uuid); + $value = $this->store->get(self::PREFIX_STATE.$uuid); if ($value !== null) { return $value; } - $forkId = $this->store->pull(self::PREFIX_FORK_ID . $uuid); + $forkId = $this->store->pull(self::PREFIX_FORK_ID.$uuid); if ($forkId === null) { return null; } /** @var null|callable(): array $callable */ - $callable = $this->store->pull(self::PREFIX_FORK_REF . $forkId); + $callable = $this->store->pull(self::PREFIX_FORK_REF.$forkId); if ($callable === null) { return null; } @@ -80,15 +80,15 @@ public function get(string $uuid): ?string $insertValues = []; $results = $callable(); foreach ($results as $rUuid => $rValue) { - $insertValues[self::PREFIX_STATE . $rUuid] = $rValue; + $insertValues[self::PREFIX_STATE.$rUuid] = $rValue; } // set new values $this->store->setMultiple($insertValues); /** @var array $uuids */ - $uuids = $this->store->pull(self::PREFIX_HASHMAP . $forkId, []); - $deleteKeys = array_map(static fn (string $uuid) => self::PREFIX_FORK_ID . $uuid, $uuids); + $uuids = $this->store->pull(self::PREFIX_HASHMAP.$forkId, []); + $deleteKeys = array_map(static fn (string $uuid) => self::PREFIX_FORK_ID.$uuid, $uuids); // delete callables by uuids $this->store->deleteMultiple($deleteKeys); @@ -98,12 +98,12 @@ public function get(string $uuid): ?string public function drop(string $uuid): void { - $deleteKeys = [self::PREFIX_STATE . $uuid]; + $deleteKeys = [self::PREFIX_STATE.$uuid]; - $forkId = $this->store->pull(self::PREFIX_FORK_ID . $uuid); + $forkId = $this->store->pull(self::PREFIX_FORK_ID.$uuid); if ($forkId !== null) { - $deleteKeys[] = self::PREFIX_FORK_REF . $forkId; - $deleteKeys[] = self::PREFIX_HASHMAP . $forkId; + $deleteKeys[] = self::PREFIX_FORK_REF.$forkId; + $deleteKeys[] = self::PREFIX_HASHMAP.$forkId; } $this->store->deleteMultiple($deleteKeys); @@ -113,7 +113,7 @@ private function getForkId(): string { do { $forkId = bin2hex(random_bytes(self::RANDOM_BYTES)); - } while ($this->store->has(self::PREFIX_FORK_REF . $forkId)); + } while ($this->store->has(self::PREFIX_FORK_REF.$forkId)); return $forkId; } diff --git a/src/Internal/Service/StorageService.php b/src/Internal/Service/StorageService.php index 97bf2b952..40bdfe1a5 100644 --- a/src/Internal/Service/StorageService.php +++ b/src/Internal/Service/StorageService.php @@ -26,7 +26,7 @@ public function flush(): bool public function forget(string $uuid): bool { - return $this->cacheRepository->forget(self::PREFIX . $uuid); + return $this->cacheRepository->forget(self::PREFIX.$uuid); } /** @@ -58,7 +58,6 @@ public function increase(string $uuid, float|int|string $value): string * @template T of non-empty-array * * @param T $uuids - * * @return non-empty-array, string> * * @throws RecordNotFoundException @@ -67,7 +66,7 @@ public function multiGet(array $uuids): array { $keys = []; foreach ($uuids as $uuid) { - $keys[self::PREFIX . $uuid] = $uuid; + $keys[self::PREFIX.$uuid] = $uuid; } $missingKeys = []; @@ -86,6 +85,7 @@ public function multiGet(array $uuids): array $uuid = $keys[$key]; if ($value === null) { $missingKeys[] = $uuid; + continue; } @@ -112,7 +112,7 @@ public function multiSync(array $inputs): bool { $values = []; foreach ($inputs as $uuid => $value) { - $values[self::PREFIX . $uuid] = $this->mathService->round($value); + $values[self::PREFIX.$uuid] = $this->mathService->round($value); } if (count($values) === 1) { @@ -126,7 +126,6 @@ public function multiSync(array $inputs): bool * @template T of non-empty-array * * @param T $inputs - * * @return non-empty-array, string> * * @throws RecordNotFoundException diff --git a/src/Internal/Service/StorageServiceInterface.php b/src/Internal/Service/StorageServiceInterface.php index 8281ee5cb..5426e808d 100644 --- a/src/Internal/Service/StorageServiceInterface.php +++ b/src/Internal/Service/StorageServiceInterface.php @@ -28,7 +28,6 @@ public function increase(string $uuid, float|int|string $value): string; * @template T of non-empty-array * * @param T $uuids - * * @return non-empty-array, string> * * @throws RecordNotFoundException @@ -44,7 +43,6 @@ public function multiSync(array $inputs): bool; * @template T of non-empty-array * * @param T $inputs - * * @return non-empty-array, string> * * @throws RecordNotFoundException diff --git a/src/Internal/Service/UuidFactoryService.php b/src/Internal/Service/UuidFactoryService.php index e08329e7b..7664e501d 100644 --- a/src/Internal/Service/UuidFactoryService.php +++ b/src/Internal/Service/UuidFactoryService.php @@ -16,7 +16,6 @@ public function __construct( public function uuid4(): string { return $this->uuidFactory->uuid4() - ->toString() - ; + ->toString(); } } diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index f5b77e99b..e2bcc4f7d 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -9,12 +9,12 @@ use Bavix\Wallet\Internal\Service\MathServiceInterface; use Bavix\Wallet\Models\Wallet as WalletModel; use Bavix\Wallet\Services\CastServiceInterface; +use function config; use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; -use function config; /** * Class Transaction. diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index 104c3363e..656232ad7 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -5,11 +5,11 @@ namespace Bavix\Wallet\Models; use Bavix\Wallet\Internal\Observers\TransferObserver; +use function config; use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; -use function config; /** * Class Transfer. diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 69dedc2bf..d3dfa9157 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -4,6 +4,8 @@ namespace Bavix\Wallet\Models; +use function app; +use function array_key_exists; use Bavix\Wallet\Interfaces\Confirmable; use Bavix\Wallet\Interfaces\Customer; use Bavix\Wallet\Interfaces\Exchangeable; @@ -13,21 +15,18 @@ use Bavix\Wallet\Internal\Service\MathServiceInterface; use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface; use Bavix\Wallet\Services\AtomicServiceInterface; -use Bavix\Wallet\Services\CastServiceInterface; use Bavix\Wallet\Services\RegulatorServiceInterface; use Bavix\Wallet\Traits\CanConfirm; use Bavix\Wallet\Traits\CanExchange; use Bavix\Wallet\Traits\CanPayFloat; use Bavix\Wallet\Traits\HasGift; +use function config; use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\RecordsNotFoundException; use Illuminate\Support\Str; -use function app; -use function array_key_exists; -use function config; /** * Class Wallet. @@ -102,13 +101,16 @@ public function getTable(): string 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. */ - if (! $this->exists && ! array_key_exists('slug', $this->attributes)) { - $this->attributes['slug'] = Str::slug($name); + if ($this->exists) { + return; + } + if (array_key_exists('slug', $this->attributes)) { + return; } + $this->attributes['slug'] = Str::slug($name); } /** @@ -140,8 +142,7 @@ public function getAvailableBalanceAttribute(): float|int|string { return $this->walletTransactions() ->where('confirmed', true) - ->sum('amount') - ; + ->sum('amount'); } /** diff --git a/src/Objects/Cart.php b/src/Objects/Cart.php index 3d1c3a327..3e44d04c8 100644 --- a/src/Objects/Cart.php +++ b/src/Objects/Cart.php @@ -16,8 +16,8 @@ use Bavix\Wallet\Internal\Exceptions\ExceptionInterface; use Bavix\Wallet\Internal\Service\MathServiceInterface; use Bavix\Wallet\Services\CastServiceInterface; -use Countable; use function count; +use Countable; final class Cart implements Countable, CartInterface { @@ -175,11 +175,11 @@ public function getBasketDto(): BasketDtoInterface throw new CartEmptyException('Cart is empty', ExceptionInterface::CART_EMPTY); } - return new BasketDto($items, $this->getMeta(), $this->getExtra()); + return new BasketDto($items, $this->meta, $this->extra); } private function productId(ProductInterface $product): string { - return $product::class . ':' . $this->castService->getModel($product)->getKey(); + return $product::class.':'.$this->castService->getModel($product)->getKey(); } } diff --git a/src/Services/AssistantService.php b/src/Services/AssistantService.php index 4c8f7a29a..67fd519cf 100644 --- a/src/Services/AssistantService.php +++ b/src/Services/AssistantService.php @@ -24,7 +24,6 @@ public function __construct( /** * @param non-empty-array $objects - * * @return non-empty-array */ public function getWallets(array $objects): array @@ -40,7 +39,6 @@ public function getWallets(array $objects): array /** * @param non-empty-array $objects - * * @return non-empty-array */ public function getUuids(array $objects): array @@ -50,7 +48,6 @@ public function getUuids(array $objects): array /** * @param non-empty-array $transactions - * * @return array */ public function getSums(array $transactions): array diff --git a/src/Services/AssistantServiceInterface.php b/src/Services/AssistantServiceInterface.php index c1378fbe7..bf33649d3 100644 --- a/src/Services/AssistantServiceInterface.php +++ b/src/Services/AssistantServiceInterface.php @@ -17,7 +17,6 @@ interface AssistantServiceInterface { /** * @param non-empty-array $objects - * * @return non-empty-array */ public function getWallets(array $objects): array; @@ -26,7 +25,6 @@ public function getWallets(array $objects): array; * Helps to quickly extract the uuid from an object. * * @param non-empty-array $objects - * * @return non-empty-array */ public function getUuids(array $objects): array; @@ -35,7 +33,6 @@ public function getUuids(array $objects): array; * Helps to quickly calculate the amount. * * @param non-empty-array $transactions - * * @return array */ public function getSums(array $transactions): array; diff --git a/src/Services/AtmService.php b/src/Services/AtmService.php index 4861dd569..5a6144caa 100644 --- a/src/Services/AtmService.php +++ b/src/Services/AtmService.php @@ -29,7 +29,6 @@ public function __construct( /** * @param non-empty-array $objects - * * @return non-empty-array */ public function makeTransactions(array $objects): array @@ -55,7 +54,6 @@ public function makeTransactions(array $objects): array /** * @param non-empty-array $objects - * * @return non-empty-array */ public function makeTransfers(array $objects): array diff --git a/src/Services/AtmServiceInterface.php b/src/Services/AtmServiceInterface.php index 511cddf9c..0955f7ee4 100644 --- a/src/Services/AtmServiceInterface.php +++ b/src/Services/AtmServiceInterface.php @@ -18,7 +18,6 @@ interface AtmServiceInterface * Helps to get to create a bunch of transaction objects. * * @param non-empty-array $objects - * * @return non-empty-array */ public function makeTransactions(array $objects): array; @@ -27,7 +26,6 @@ public function makeTransactions(array $objects): array; * Helps to get to create a bunch of transfer objects. * * @param non-empty-array $objects - * * @return non-empty-array */ public function makeTransfers(array $objects): array; diff --git a/src/Services/AtomicServiceInterface.php b/src/Services/AtomicServiceInterface.php index 284456597..42f5c6d25 100644 --- a/src/Services/AtomicServiceInterface.php +++ b/src/Services/AtomicServiceInterface.php @@ -18,6 +18,7 @@ interface AtomicServiceInterface * The method atomically locks the transaction for other concurrent requests. * * @template T + * * @param callable(): T $callback * @return T * @@ -32,6 +33,7 @@ public function block(Wallet $object, callable $callback): mixed; * caution, generates N requests to the lock service. * * @template T + * * @param non-empty-array $objects * @param callable(): T $callback * @return T diff --git a/src/Services/BookkeeperServiceInterface.php b/src/Services/BookkeeperServiceInterface.php index 9c95c185c..711f5f685 100644 --- a/src/Services/BookkeeperServiceInterface.php +++ b/src/Services/BookkeeperServiceInterface.php @@ -30,7 +30,6 @@ public function increase(Wallet $wallet, float|int|string $value): string; * @template T of non-empty-array * * @param T $wallets - * * @return non-empty-array, string> */ public function multiAmount(array $wallets): array; @@ -47,7 +46,6 @@ public function multiSync(array $balances): bool; * * @param non-empty-array, Wallet> $wallets * @param T $incrementValues - * * @return non-empty-array, string> * * @throws RecordNotFoundException diff --git a/src/Services/DiscountService.php b/src/Services/DiscountService.php index d9919af87..1d8bdab55 100644 --- a/src/Services/DiscountService.php +++ b/src/Services/DiscountService.php @@ -15,10 +15,13 @@ final class DiscountService implements DiscountServiceInterface { public function getDiscount(Wallet $customer, Wallet $product): int { - if ($customer instanceof Customer && $product instanceof Discount) { - return (int) $product->getPersonalDiscount($customer); + if (! $customer instanceof Customer) { + return 0; + } + if (! $product instanceof Discount) { + return 0; } - return 0; + return (int) $product->getPersonalDiscount($customer); } } diff --git a/src/Services/PurchaseService.php b/src/Services/PurchaseService.php index bb18499c3..fe77ac706 100644 --- a/src/Services/PurchaseService.php +++ b/src/Services/PurchaseService.php @@ -48,8 +48,7 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool ->orderBy('id', 'desc') ->limit($productCounts[$wallet->uuid]) ->get() - ->all() - ; + ->all(); } return array_merge(...$arrays); diff --git a/src/Services/TransactionService.php b/src/Services/TransactionService.php index c5b43d081..fae7e23d6 100644 --- a/src/Services/TransactionService.php +++ b/src/Services/TransactionService.php @@ -53,10 +53,9 @@ public function makeOne( /** * @param non-empty-array $wallets * @param non-empty-array $objects + * @return non-empty-array * * @throws RecordNotFoundException - * - * @return non-empty-array */ public function apply(array $wallets, array $objects): array { diff --git a/src/Services/TransactionServiceInterface.php b/src/Services/TransactionServiceInterface.php index 989e52cfb..b4991a29c 100644 --- a/src/Services/TransactionServiceInterface.php +++ b/src/Services/TransactionServiceInterface.php @@ -30,10 +30,9 @@ public function makeOne( /** * @param non-empty-array $wallets * @param non-empty-array $objects + * @return non-empty-array * * @throws RecordNotFoundException - * - * @return non-empty-array */ public function apply(array $wallets, array $objects): array; } diff --git a/src/Services/TransferService.php b/src/Services/TransferService.php index fc2b40a8d..f2e508aba 100644 --- a/src/Services/TransferService.php +++ b/src/Services/TransferService.php @@ -40,13 +40,12 @@ public function updateStatusByIds(string $status, array $ids): bool /** * @param non-empty-array $objects + * @return non-empty-array * * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function apply(array $objects): array { diff --git a/src/Services/TransferServiceInterface.php b/src/Services/TransferServiceInterface.php index ddc7de7df..a50a453c6 100644 --- a/src/Services/TransferServiceInterface.php +++ b/src/Services/TransferServiceInterface.php @@ -23,13 +23,12 @@ public function updateStatusByIds(string $status, array $ids): bool; /** * @param non-empty-array $objects + * @return non-empty-array * * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function apply(array $objects): array; } diff --git a/src/Traits/CanPay.php b/src/Traits/CanPay.php index 39c8e8d27..52d07d3d9 100644 --- a/src/Traits/CanPay.php +++ b/src/Traits/CanPay.php @@ -14,11 +14,12 @@ use Bavix\Wallet\Internal\Exceptions\TransactionFailedException; use Bavix\Wallet\Models\Transfer; use Bavix\Wallet\Objects\Cart; -use Illuminate\Database\RecordsNotFoundException; use function current; +use Illuminate\Database\RecordsNotFoundException; /** * @psalm-require-extends \Illuminate\Database\Eloquent\Model + * * @psalm-require-implements \Bavix\Wallet\Interfaces\Customer */ trait CanPay diff --git a/src/Traits/CanPayFloat.php b/src/Traits/CanPayFloat.php index d4c892b73..23e2c07f4 100644 --- a/src/Traits/CanPayFloat.php +++ b/src/Traits/CanPayFloat.php @@ -6,6 +6,7 @@ /** * @psalm-require-extends \Illuminate\Database\Eloquent\Model + * * @psalm-require-implements \Bavix\Wallet\Interfaces\Customer */ trait CanPayFloat diff --git a/src/Traits/CartPay.php b/src/Traits/CartPay.php index 899b1fa59..2c6c9db94 100644 --- a/src/Traits/CartPay.php +++ b/src/Traits/CartPay.php @@ -26,11 +26,12 @@ use Bavix\Wallet\Services\PrepareServiceInterface; use Bavix\Wallet\Services\PurchaseServiceInterface; use Bavix\Wallet\Services\TransferServiceInterface; -use Illuminate\Database\RecordsNotFoundException; use function count; +use Illuminate\Database\RecordsNotFoundException; /** * @psalm-require-extends \Illuminate\Database\Eloquent\Model + * * @psalm-require-implements \Bavix\Wallet\Interfaces\Customer */ trait CartPay @@ -38,6 +39,8 @@ trait CartPay use HasWallet; /** + * @return non-empty-array + * * @throws ProductEnded * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -45,8 +48,6 @@ trait CartPay * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function payFreeCart(CartInterface $cart): array { @@ -101,6 +102,8 @@ public function safePayCart(CartInterface $cart, bool $force = false): array } /** + * @return non-empty-array + * * @throws ProductEnded * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -108,8 +111,6 @@ public function safePayCart(CartInterface $cart, bool $force = false): array * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function payCart(CartInterface $cart, bool $force = false): array { @@ -132,7 +133,7 @@ public function payCart(CartInterface $cart, bool $force = false): array $assistantService = app(AssistantServiceInterface::class); foreach ($cart->getBasketDto()->items() as $item) { foreach ($item->getItems() as $product) { - $productId = $product::class . ':' . $castService->getModel($product)->getKey(); + $productId = $product::class.':'.$castService->getModel($product)->getKey(); $pricePerItem = $item->getPricePerItem(); if ($pricePerItem === null) { $prices[$productId] ??= $product->getAmountProduct($this); @@ -162,13 +163,13 @@ public function payCart(CartInterface $cart, bool $force = false): array } /** + * @return non-empty-array + * * @throws ProductEnded * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface - * - * @return non-empty-array */ public function forcePayCart(CartInterface $cart): array { @@ -228,7 +229,7 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts $assistantService->getMeta($basketDto, $product) ); - ++$index; + $index++; } } @@ -243,8 +244,7 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts $transferService->apply($objects); return $transferService - ->updateStatusByIds(Transfer::STATUS_REFUND, $transferIds) - ; + ->updateStatusByIds(Transfer::STATUS_REFUND, $transferIds); }); } @@ -305,8 +305,7 @@ public function paid(ProductInterface $product, bool $gifts = false): ?Transfer { $cart = app(Cart::class)->withItem($product); $purchases = app(PurchaseServiceInterface::class) - ->already($this, $cart->getBasketDto(), $gifts) - ; + ->already($this, $cart->getBasketDto(), $gifts); return current($purchases) ?: null; } diff --git a/src/Traits/HasGift.php b/src/Traits/HasGift.php index d98d0fe33..9063cc1f0 100644 --- a/src/Traits/HasGift.php +++ b/src/Traits/HasGift.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Traits; +use function app; use Bavix\Wallet\Exceptions\BalanceIsEmpty; use Bavix\Wallet\Exceptions\InsufficientFunds; use Bavix\Wallet\Interfaces\ProductInterface; @@ -22,7 +23,6 @@ use Bavix\Wallet\Services\TaxServiceInterface; use Bavix\Wallet\Services\TransactionServiceInterface; use Illuminate\Database\RecordsNotFoundException; -use function app; /** * Trait HasGift. diff --git a/src/Traits/HasWallet.php b/src/Traits/HasWallet.php index a035e3ca2..0dcff74cc 100644 --- a/src/Traits/HasWallet.php +++ b/src/Traits/HasWallet.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Traits; +use function app; use Bavix\Wallet\Exceptions\AmountInvalid; use Bavix\Wallet\Exceptions\BalanceIsEmpty; use Bavix\Wallet\Exceptions\InsufficientFunds; @@ -22,11 +23,10 @@ use Bavix\Wallet\Services\RegulatorServiceInterface; use Bavix\Wallet\Services\TransactionServiceInterface; use Bavix\Wallet\Services\TransferServiceInterface; +use function config; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\RecordsNotFoundException; -use function app; -use function config; /** * Trait HasWallet. @@ -34,7 +34,9 @@ * @property WalletModel $wallet * @property string $balance * @property int $balanceInt + * * @psalm-require-extends \Illuminate\Database\Eloquent\Model + * * @psalm-require-implements \Bavix\Wallet\Interfaces\Wallet */ trait HasWallet @@ -81,8 +83,7 @@ public function walletTransactions(): HasMany { return app(CastServiceInterface::class) ->getWallet($this, false) - ->hasMany(config('wallet.transaction.model', Transaction::class), 'wallet_id') - ; + ->hasMany(config('wallet.transaction.model', Transaction::class), 'wallet_id'); } /** @@ -94,8 +95,7 @@ public function transactions(): MorphMany { return app(CastServiceInterface::class) ->getHolder($this) - ->morphMany(config('wallet.transaction.model', Transaction::class), 'payable') - ; + ->morphMany(config('wallet.transaction.model', Transaction::class), 'payable'); } /** @@ -205,8 +205,7 @@ public function forceTransfer( ): Transfer { return app(AtomicServiceInterface::class)->block($this, function () use ($wallet, $amount, $meta): Transfer { $transferLazyDto = app(PrepareServiceInterface::class) - ->transferLazy($this, $wallet, Transfer::STATUS_TRANSFER, $amount, $meta) - ; + ->transferLazy($this, $wallet, Transfer::STATUS_TRANSFER, $amount, $meta); $transfers = app(TransferServiceInterface::class)->apply([$transferLazyDto]); @@ -224,8 +223,7 @@ public function transfers(): HasMany /** @var Wallet $this */ return app(CastServiceInterface::class) ->getWallet($this, false) - ->hasMany(config('wallet.transfer.model', Transfer::class), 'from_id') - ; + ->hasMany(config('wallet.transfer.model', Transfer::class), 'from_id'); } /** @@ -237,7 +235,6 @@ public function receivedTransfers(): HasMany { return app(CastServiceInterface::class) ->getWallet($this, false) - ->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id') - ; + ->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id'); } } diff --git a/src/Traits/HasWalletFloat.php b/src/Traits/HasWalletFloat.php index 7dc1d5784..91ccbeec9 100644 --- a/src/Traits/HasWalletFloat.php +++ b/src/Traits/HasWalletFloat.php @@ -23,7 +23,9 @@ * * @property string $balanceFloat * @property float $balanceFloatNum + * * @psalm-require-extends \Illuminate\Database\Eloquent\Model + * * @psalm-require-implements \Bavix\Wallet\Interfaces\WalletFloat */ trait HasWalletFloat diff --git a/src/Traits/HasWallets.php b/src/Traits/HasWallets.php index 1bc559163..2628c53ca 100644 --- a/src/Traits/HasWallets.php +++ b/src/Traits/HasWallets.php @@ -4,18 +4,19 @@ namespace Bavix\Wallet\Traits; +use function array_key_exists; use Bavix\Wallet\Internal\Exceptions\ModelNotFoundException; use Bavix\Wallet\Models\Wallet as WalletModel; use Bavix\Wallet\Services\WalletServiceInterface; +use function config; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Support\Collection; -use function array_key_exists; -use function config; /** * Trait HasWallets To use a trait, you must add HasWallet trait. * * @property Collection $wallets + * * @psalm-require-extends \Illuminate\Database\Eloquent\Model */ trait HasWallets diff --git a/src/Traits/MorphOneWallet.php b/src/Traits/MorphOneWallet.php index 196ba658d..b3b991aea 100644 --- a/src/Traits/MorphOneWallet.php +++ b/src/Traits/MorphOneWallet.php @@ -12,6 +12,7 @@ * Trait MorphOneWallet. * * @property WalletModel $wallet + * * @psalm-require-extends \Illuminate\Database\Eloquent\Model */ trait MorphOneWallet @@ -50,8 +51,7 @@ public function wallet(): MorphOne if ($model->exists) { $wallet->setRelation('holder', $model->withoutRelations()); } - }) - ; + }); } public function getWalletAttribute(): ?WalletModel diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index bb121d86b..4461136e3 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -108,6 +108,9 @@ use Bavix\Wallet\Services\TransferServiceInterface; use Bavix\Wallet\Services\WalletService; use Bavix\Wallet\Services\WalletServiceInterface; +use function config; +use function dirname; +use function function_exists; use Illuminate\Contracts\Cache\Factory as CacheFactory; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Database\Events\TransactionBeginning; @@ -116,9 +119,6 @@ use Illuminate\Database\Events\TransactionRolledBack; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; -use function config; -use function dirname; -use function function_exists; final class WalletServiceProvider extends ServiceProvider implements DeferrableProvider { @@ -127,7 +127,7 @@ final class WalletServiceProvider extends ServiceProvider implements DeferrableP */ public function boot(): void { - $this->loadTranslationsFrom(dirname(__DIR__) . '/resources/lang', 'wallet'); + $this->loadTranslationsFrom(dirname(__DIR__).'/resources/lang', 'wallet'); Event::listen(TransactionBeginning::class, Internal\Listeners\TransactionBeginningListener::class); Event::listen(TransactionCommitting::class, Internal\Listeners\TransactionCommittingListener::class); @@ -141,17 +141,17 @@ public function boot(): void // @codeCoverageIgnoreEnd if (WalletConfigure::isRunsMigrations()) { - $this->loadMigrationsFrom([dirname(__DIR__) . '/database']); + $this->loadMigrationsFrom([dirname(__DIR__).'/database']); } if (function_exists('config_path')) { $this->publishes([ - dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'), + dirname(__DIR__).'/config/config.php' => config_path('wallet.php'), ], 'laravel-wallet-config'); } $this->publishes([ - dirname(__DIR__) . '/database/' => database_path('migrations'), + dirname(__DIR__).'/database/' => database_path('migrations'), ], 'laravel-wallet-migrations'); } @@ -160,7 +160,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'); /** * @var array{ diff --git a/tests/Infra/Helpers/Config.php b/tests/Infra/Helpers/Config.php index 8266ca187..f0b794b84 100644 --- a/tests/Infra/Helpers/Config.php +++ b/tests/Infra/Helpers/Config.php @@ -16,7 +16,6 @@ public static function string(string $key, string $default): string /** * @param class-string $default - * * @return class-string */ public static function classString(string $key, string $default): string diff --git a/tests/Infra/Listeners/TransactionCreatedThrowListener.php b/tests/Infra/Listeners/TransactionCreatedThrowListener.php index 65e4dc9c1..4b0099f86 100644 --- a/tests/Infra/Listeners/TransactionCreatedThrowListener.php +++ b/tests/Infra/Listeners/TransactionCreatedThrowListener.php @@ -13,10 +13,9 @@ public function handle(TransactionCreatedEventInterface $transactionCreatedEvent { $type = $transactionCreatedEvent->getType(); $createdAt = $transactionCreatedEvent->getCreatedAt() - ->format(\DateTimeInterface::ATOM) - ; + ->format(\DateTimeInterface::ATOM); - $message = hash('sha256', $type . $createdAt); + $message = hash('sha256', $type.$createdAt); throw new UnknownEventException($message, $transactionCreatedEvent->getId()); } diff --git a/tests/Infra/Listeners/WalletCreatedThrowListener.php b/tests/Infra/Listeners/WalletCreatedThrowListener.php index 62b8bc14b..5b5de36b5 100644 --- a/tests/Infra/Listeners/WalletCreatedThrowListener.php +++ b/tests/Infra/Listeners/WalletCreatedThrowListener.php @@ -15,10 +15,9 @@ public function handle(WalletCreatedEventInterface $walletCreatedEvent): never $holderType = $walletCreatedEvent->getHolderType(); $uuid = $walletCreatedEvent->getWalletUuid(); $createdAt = $walletCreatedEvent->getCreatedAt() - ->format(DateTimeInterface::ATOM) - ; + ->format(DateTimeInterface::ATOM); - $message = hash('sha256', $holderType . $uuid . $createdAt); + $message = hash('sha256', $holderType.$uuid.$createdAt); $code = $walletCreatedEvent->getWalletId() + (int) $walletCreatedEvent->getHolderId(); assert($code > 1); diff --git a/tests/Infra/Models/Item.php b/tests/Infra/Models/Item.php index 69d56cbe1..3a32568c8 100644 --- a/tests/Infra/Models/Item.php +++ b/tests/Infra/Models/Item.php @@ -41,7 +41,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof Transfer; } public function getAmountProduct(Customer $customer): int @@ -59,7 +59,6 @@ public function getMetaProduct(): ?array /** * @param int[] $walletIds - * * @return HasMany */ public function boughtGoods(array $walletIds): HasMany @@ -68,7 +67,6 @@ public function boughtGoods(array $walletIds): HasMany ->getWallet($this) ->hasMany(Config::classString('wallet.transfer.model', Transfer::class), 'to_id') ->where('status', Transfer::STATUS_PAID) - ->whereIn('from_id', $walletIds) - ; + ->whereIn('from_id', $walletIds); } } diff --git a/tests/Infra/Models/ItemDiscount.php b/tests/Infra/Models/ItemDiscount.php index 8d0e78567..4d2ef9bf8 100644 --- a/tests/Infra/Models/ItemDiscount.php +++ b/tests/Infra/Models/ItemDiscount.php @@ -41,7 +41,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemDiscountTax.php b/tests/Infra/Models/ItemDiscountTax.php index 48a41b0c6..1da44412f 100644 --- a/tests/Infra/Models/ItemDiscountTax.php +++ b/tests/Infra/Models/ItemDiscountTax.php @@ -42,7 +42,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemMaxTax.php b/tests/Infra/Models/ItemMaxTax.php index 3c3fa3955..dd41376f4 100644 --- a/tests/Infra/Models/ItemMaxTax.php +++ b/tests/Infra/Models/ItemMaxTax.php @@ -41,7 +41,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemMeta.php b/tests/Infra/Models/ItemMeta.php index f6adb0a28..2626725c4 100644 --- a/tests/Infra/Models/ItemMeta.php +++ b/tests/Infra/Models/ItemMeta.php @@ -42,7 +42,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemMinTax.php b/tests/Infra/Models/ItemMinTax.php index b2b951842..b607c8045 100644 --- a/tests/Infra/Models/ItemMinTax.php +++ b/tests/Infra/Models/ItemMinTax.php @@ -41,7 +41,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemMultiPrice.php b/tests/Infra/Models/ItemMultiPrice.php index ed8696636..334410de4 100644 --- a/tests/Infra/Models/ItemMultiPrice.php +++ b/tests/Infra/Models/ItemMultiPrice.php @@ -46,7 +46,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemTax.php b/tests/Infra/Models/ItemTax.php index e9a812695..0483a8378 100644 --- a/tests/Infra/Models/ItemTax.php +++ b/tests/Infra/Models/ItemTax.php @@ -41,7 +41,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/ItemWallet.php b/tests/Infra/Models/ItemWallet.php index 35d30cffe..0e5a3034a 100644 --- a/tests/Infra/Models/ItemWallet.php +++ b/tests/Infra/Models/ItemWallet.php @@ -42,7 +42,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result; } - return $result && ! $customer->paid($this); + return $result && ! $customer->paid($this) instanceof \Bavix\Wallet\Models\Transfer; } public function getAmountProduct(Customer $customer): int diff --git a/tests/Infra/Models/UserDynamic.php b/tests/Infra/Models/UserDynamic.php index af81cff8b..dea29a1df 100644 --- a/tests/Infra/Models/UserDynamic.php +++ b/tests/Infra/Models/UserDynamic.php @@ -30,6 +30,6 @@ public function getTable(): string public function getDynamicDefaultSlug(): string { - return 'default-' . $this->email; + return 'default-'.$this->email; } } diff --git a/tests/Infra/TestCase.php b/tests/Infra/TestCase.php index 6ecc4ad17..ad11c2cc7 100644 --- a/tests/Infra/TestCase.php +++ b/tests/Infra/TestCase.php @@ -37,7 +37,6 @@ final public function expectExceptionMessageStrict(mixed $message): void /** * @param Application $app - * * @return non-empty-array */ final protected function getPackageProviders($app): array diff --git a/tests/Infra/TestServiceProvider.php b/tests/Infra/TestServiceProvider.php index 351b03e0b..72e9aa96a 100644 --- a/tests/Infra/TestServiceProvider.php +++ b/tests/Infra/TestServiceProvider.php @@ -10,6 +10,6 @@ final class TestServiceProvider extends ServiceProvider { public function boot(): void { - $this->loadMigrationsFrom([dirname(__DIR__) . '/migrations']); + $this->loadMigrationsFrom([dirname(__DIR__).'/migrations']); } } diff --git a/tests/Units/Api/TransactionHandlerTest.php b/tests/Units/Api/TransactionHandlerTest.php index 10e475f6f..9cd7b480e 100644 --- a/tests/Units/Api/TransactionHandlerTest.php +++ b/tests/Units/Api/TransactionHandlerTest.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Test\Units\Api; +use function app; use Bavix\Wallet\External\Api\TransactionFloatQuery; use Bavix\Wallet\External\Api\TransactionQuery; use Bavix\Wallet\External\Api\TransactionQueryHandlerInterface; @@ -11,7 +12,6 @@ use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\PackageModels\Transaction; use Bavix\Wallet\Test\Infra\TestCase; -use function app; /** * @internal diff --git a/tests/Units/Api/TransferHandlerTest.php b/tests/Units/Api/TransferHandlerTest.php index 819fef55b..b3623c721 100644 --- a/tests/Units/Api/TransferHandlerTest.php +++ b/tests/Units/Api/TransferHandlerTest.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Test\Units\Api; +use function app; use Bavix\Wallet\External\Api\TransferFloatQuery; use Bavix\Wallet\External\Api\TransferQuery; use Bavix\Wallet\External\Api\TransferQueryHandlerInterface; @@ -11,7 +12,6 @@ use Bavix\Wallet\Test\Infra\Factories\BuyerFactory; use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\TestCase; -use function app; /** * @internal @@ -41,39 +41,67 @@ public function testWalletNotExists(): void null, null, '598c184c-e6d6-4fc2-9640-c1c7acb38093', - ['type' => 'first'], + [ + 'type' => 'first', + ], ), ), - new TransferQuery($from, $to, 100, + new TransferQuery( + $from, + $to, + 100, new Extra( null, null, 'f303d60d-c2de-45d0-b9ed-e1487429709a', - ['type' => 'second'], - )), - new TransferQuery($to, $from, 50, + [ + 'type' => 'second', + ], + ) + ), + new TransferQuery( + $to, + $from, + 50, new Extra( null, null, '7f0175fe-99cc-4058-92c6-157f0da18243', - ['type' => 'third'], - )), - new TransferFloatQuery($to, $from, .50, + [ + 'type' => 'third', + ], + ) + ), + new TransferFloatQuery( + $to, + $from, + .50, new Extra( null, null, '1a7326a6-dfdf-4ec8-afc4-cb21cf1f43c6', - ['type' => 'fourth'], - )), + [ + 'type' => 'fourth', + ], + ) + ), ]); self::assertSame(-100, $from->balanceInt); self::assertSame(100, $to->balanceInt); self::assertCount(4, $transfers); - self::assertSame(['type' => 'first'], $transfers['598c184c-e6d6-4fc2-9640-c1c7acb38093']->extra); - self::assertSame(['type' => 'second'], $transfers['f303d60d-c2de-45d0-b9ed-e1487429709a']->extra); - self::assertSame(['type' => 'third'], $transfers['7f0175fe-99cc-4058-92c6-157f0da18243']->extra); - self::assertSame(['type' => 'fourth'], $transfers['1a7326a6-dfdf-4ec8-afc4-cb21cf1f43c6']->extra); + self::assertSame([ + 'type' => 'first', + ], $transfers['598c184c-e6d6-4fc2-9640-c1c7acb38093']->extra); + self::assertSame([ + 'type' => 'second', + ], $transfers['f303d60d-c2de-45d0-b9ed-e1487429709a']->extra); + self::assertSame([ + 'type' => 'third', + ], $transfers['7f0175fe-99cc-4058-92c6-157f0da18243']->extra); + self::assertSame([ + 'type' => 'fourth', + ], $transfers['1a7326a6-dfdf-4ec8-afc4-cb21cf1f43c6']->extra); } } diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index 294f92cd4..d735e1994 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Test\Units\Domain; +use function app; use Bavix\Wallet\Models\Wallet; use Bavix\Wallet\Services\BookkeeperServiceInterface; use Bavix\Wallet\Services\RegulatorServiceInterface; @@ -12,7 +13,6 @@ use Bavix\Wallet\Test\Infra\TestCase; use PDOException; use PHPUnit\Framework\MockObject\MockObject; -use function app; /** * @internal @@ -142,8 +142,7 @@ public function testSimple(): void // databases that do not support fk will not delete data... need to help them $wallet->transactions() ->where('wallet_id', $key) - ->delete() - ; + ->delete(); self::assertFalse($wallet->exists); self::assertSame(1100, (int) $result); @@ -187,30 +186,24 @@ public function testThrowUpdate(): void /** @var MockObject&Wallet $mockQuery */ $mockQuery = $this->createMock($wallet->newQuery()::class); $mockQuery->method('whereKey') - ->willReturn($mockQuery) - ; + ->willReturn($mockQuery); $mockQuery->method('update') - ->willThrowException(new PDOException()) - ; + ->willThrowException(new PDOException()); /** @var MockObject&Wallet $mockWallet */ $mockWallet = $this->createMock(Wallet::class); $mockWallet->method('getBalanceAttribute') - ->willReturn('125') - ; + ->willReturn('125'); $mockWallet->method('newQuery') - ->willReturn($mockQuery) - ; + ->willReturn($mockQuery); $mockWallet->method('getKey') - ->willReturn(1) - ; + ->willReturn(1); $mockWallet->newQuery() ->whereKey(1) ->update([ 'balance' => 100, - ]) - ; + ]); } public function testEqualWallet(): void diff --git a/tests/Units/Domain/BlockTest.php b/tests/Units/Domain/BlockTest.php index a3defc4f3..cea263307 100644 --- a/tests/Units/Domain/BlockTest.php +++ b/tests/Units/Domain/BlockTest.php @@ -58,8 +58,7 @@ public function testBlockTransfer(): void $transaction = $buyer2->wallet->walletTransactions() ->where('meta->type', 'block') ->where('confirmed', false) - ->first() - ; + ->first(); self::assertTrue($transfer->deposit->is($transaction)); self::assertTrue($buyer2->wallet->confirm($transaction)); diff --git a/tests/Units/Domain/CartReceivingTest.php b/tests/Units/Domain/CartReceivingTest.php index f4b330340..7181cdf1c 100644 --- a/tests/Units/Domain/CartReceivingTest.php +++ b/tests/Units/Domain/CartReceivingTest.php @@ -15,8 +15,8 @@ use Bavix\Wallet\Test\Infra\Models\ItemMeta; use Bavix\Wallet\Test\Infra\PackageModels\Transaction; use Bavix\Wallet\Test\Infra\TestCase; -use Illuminate\Database\Eloquent\Collection; use function count; +use Illuminate\Database\Eloquent\Collection; /** * @internal @@ -52,8 +52,7 @@ public function testCartMeta(): void ->withItem($product, receiving: $receiving) ->withMeta([ 'type' => $expected, - ]) - ; + ]); $amount = $cart->getTotal($buyer); diff --git a/tests/Units/Domain/CartTest.php b/tests/Units/Domain/CartTest.php index 58eb8b507..bb697f889 100644 --- a/tests/Units/Domain/CartTest.php +++ b/tests/Units/Domain/CartTest.php @@ -19,8 +19,8 @@ use Bavix\Wallet\Test\Infra\Models\ItemMeta; use Bavix\Wallet\Test\Infra\PackageModels\Transaction; use Bavix\Wallet\Test\Infra\TestCase; -use Illuminate\Database\Eloquent\Collection; use function count; +use Illuminate\Database\Eloquent\Collection; /** * @internal @@ -38,9 +38,12 @@ public function testCartClone(): void $cartWithItems = $cart->withItems([$product]); $cartWithMeta = $cart - ->withMeta(['product_id' => $product->getKey()]) - ->withExtra(['products' => count($cartWithItems->getItems())]) - ; + ->withMeta([ + 'product_id' => $product->getKey(), + ]) + ->withExtra([ + 'products' => count($cartWithItems->getItems()), + ]); self::assertCount(0, $cart->getItems()); self::assertCount(1, $cartWithItems->getItems()); @@ -69,8 +72,7 @@ public function testCartMeta(): void ->withItems([$product]) ->withMeta([ 'type' => $expected, - ]) - ; + ]); self::assertSame(0, $buyer->balanceInt); self::assertNotNull($buyer->deposit($cart->getTotal($buyer))); @@ -111,8 +113,7 @@ public function testCartMetaItemNoMeta(): void ->withItems([$product]) ->withMeta([ 'type' => $expected, - ]) - ; + ]); self::assertSame(0, $buyer->balanceInt); self::assertNotNull($buyer->deposit($cart->getTotal($buyer))); @@ -184,7 +185,7 @@ public function testCartQuantity(): void $amount = 0; $price = 0; $productsCount = count($products); - for ($i = 0; $i < $productsCount - 1; ++$i) { + for ($i = 0; $i < $productsCount - 1; $i++) { self::assertNotNull($products[$i]); $rnd = random_int(1, 5); @@ -220,7 +221,7 @@ public function testModelNotFoundException(): void $cart = app(Cart::class); $total = 0; $productsCount = count($products); - for ($i = 0; $i < $productsCount - 1; ++$i) { + for ($i = 0; $i < $productsCount - 1; $i++) { self::assertNotNull($products[$i]); $rnd = random_int(1, 5); @@ -238,8 +239,7 @@ public function testModelNotFoundException(): void self::assertCount($total, $transfers); $refundCart = app(Cart::class) - ->withItems($products) // all goods - ; + ->withItems($products); // all goods $buyer->refundCart($refundCart); } @@ -268,8 +268,7 @@ public function testBoughtGoods(): void foreach ($products as $product) { $count = $product ->boughtGoods([$buyer->wallet->getKey()]) - ->count() - ; + ->count(); self::assertSame($total[$product->getKey()], $count); } @@ -335,8 +334,7 @@ public function testWithdrawal(): void $balance = $buyer->wallet::query() ->whereKey($buyer->wallet->getKey()) ->getQuery() - ->value('balance') - ; + ->value('balance'); self::assertSame(0, (int) $balance); } diff --git a/tests/Units/Domain/DiscountTest.php b/tests/Units/Domain/DiscountTest.php index 87e7ca86e..8d4b9d95a 100644 --- a/tests/Units/Domain/DiscountTest.php +++ b/tests/Units/Domain/DiscountTest.php @@ -13,9 +13,9 @@ use Bavix\Wallet\Test\Infra\Factories\ItemDiscountFactory; use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\Models\ItemDiscount; -use Bavix\Wallet\Test\Infra\TestCase; use Bavix\Wallet\Test\Infra\PackageModels\Transaction as InfraTransaction; use Bavix\Wallet\Test\Infra\PackageModels\Wallet as InfraWallet; +use Bavix\Wallet\Test\Infra\TestCase; /** * @internal diff --git a/tests/Units/Domain/EagerLoadingTest.php b/tests/Units/Domain/EagerLoadingTest.php index 3df738a08..889d02f4e 100644 --- a/tests/Units/Domain/EagerLoadingTest.php +++ b/tests/Units/Domain/EagerLoadingTest.php @@ -32,8 +32,7 @@ public function testUuidDuplicate(): void /** @var Collection $buyers */ $buyers = Buyer::with('wallet') ->whereIn('id', $buyerTimes->pluck('id')->toArray()) - ->paginate(10) - ; + ->paginate(10); $uuids = []; $balances = []; diff --git a/tests/Units/Domain/EventTest.php b/tests/Units/Domain/EventTest.php index 30c7f5f40..b57446dab 100644 --- a/tests/Units/Domain/EventTest.php +++ b/tests/Units/Domain/EventTest.php @@ -103,7 +103,7 @@ public function testWalletCreatedThrowListener(): void $uuid = $buyer->wallet->uuid; $createdAt = app(ClockServiceInterface::class)->now()->format(DateTimeInterface::ATOM); - $message = hash('sha256', $holderType . $uuid . $createdAt); + $message = hash('sha256', $holderType.$uuid.$createdAt); // unit $this->expectException(UnknownEventException::class); @@ -127,7 +127,7 @@ public function testMultiWalletCreatedThrowListener(): void $holderType = $user->getMorphClass(); $createdAt = app(ClockServiceInterface::class)->now()->format(DateTimeInterface::ATOM); - $message = hash('sha256', $holderType . $uuid . $createdAt); + $message = hash('sha256', $holderType.$uuid.$createdAt); // unit $this->expectException(UnknownEventException::class); @@ -185,10 +185,9 @@ public function testTransactionCreatedThrowListener(): void $createdAt = app(ClockServiceInterface::class) ->now() - ->format(DateTimeInterface::ATOM) - ; + ->format(DateTimeInterface::ATOM); - $message = hash('sha256', Transaction::TYPE_DEPOSIT . $createdAt); + $message = hash('sha256', Transaction::TYPE_DEPOSIT.$createdAt); // unit $this->expectException(UnknownEventException::class); diff --git a/tests/Units/Domain/ExchangeTest.php b/tests/Units/Domain/ExchangeTest.php index e1ccfabcb..a3bdc0dce 100644 --- a/tests/Units/Domain/ExchangeTest.php +++ b/tests/Units/Domain/ExchangeTest.php @@ -118,8 +118,7 @@ public function testRate(): void self::assertInstanceOf($superWallet->holder_type, $user); $rate = app(ExchangeServiceInterface::class) - ->convertTo($usd->currency, $rub->currency, 1000) - ; + ->convertTo($usd->currency, $rub->currency, 1000); self::assertSame(67610., (float) $rate); } @@ -127,14 +126,12 @@ public function testRate(): void public function testExchange(): void { $rate = app(ExchangeServiceInterface::class) - ->convertTo('USD', 'RUB', 1) - ; + ->convertTo('USD', 'RUB', 1); self::assertSame(67.61, (float) $rate); $rate = app(ExchangeServiceInterface::class) - ->convertTo('RUB', 'USD', 1) - ; + ->convertTo('RUB', 'USD', 1); self::assertSame(1 / 67.61, (float) $rate); } @@ -144,8 +141,7 @@ public function testExchangeUsdToBtc(): void app()->bind(ExchangeServiceInterface::class, ExchangeUsdToBtcService::class); $rate = (float) app(ExchangeServiceInterface::class) - ->convertTo('USD', 'BTC', 1) - ; + ->convertTo('USD', 'BTC', 1); self::assertSame(0.004636, $rate); diff --git a/tests/Units/Domain/ExtraTest.php b/tests/Units/Domain/ExtraTest.php index e9aa9d755..a62625df7 100644 --- a/tests/Units/Domain/ExtraTest.php +++ b/tests/Units/Domain/ExtraTest.php @@ -41,7 +41,9 @@ public function testExtraTransferWithdraw(): void ], false ), - extra: ['msg' => 'hello world'], + extra: [ + 'msg' => 'hello world', + ], ) ); diff --git a/tests/Units/Domain/MultiWalletTest.php b/tests/Units/Domain/MultiWalletTest.php index 68ac1b2cd..ee756389d 100644 --- a/tests/Units/Domain/MultiWalletTest.php +++ b/tests/Units/Domain/MultiWalletTest.php @@ -28,8 +28,8 @@ use Bavix\Wallet\Test\Infra\PackageModels\Wallet; use Bavix\Wallet\Test\Infra\TestCase; use Illuminate\Database\QueryException; -use Throwable; use function range; +use Throwable; /** * @internal @@ -175,8 +175,7 @@ public function testGetWalletOrFailError(): void $this->expectException(ModelNotFoundException::class); $userMulti - ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')) - ; + ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')); } /** @@ -193,8 +192,7 @@ public function testGetWalletOrFailSuccess(): void $userMulti->deposit(1); $walletResult = $userMulti - ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')) - ; + ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')); self::assertSame($uuid, $walletResult->uuid); } @@ -210,8 +208,7 @@ public function testTransferWalletNotExists(): void /** @var UserMulti $userMulti */ $userMulti = UserMultiFactory::new()->create(); $userMulti - ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')) - ; + ->getWalletOrFail(Config::string('wallet.wallet.default.slug', 'default')); } public function testInvalidDeposit(): void @@ -449,8 +446,7 @@ public function testGetWallet(): void ->create([ 'name' => 'Test2', 'uuid' => $uuid, - ]) - ; + ]); self::assertNotNull($test2->refresh()); self::assertSame($uuid, $test2->uuid); @@ -668,7 +664,7 @@ public function testMultiWalletTransactionState(): void $wallets = []; foreach (range(1, 10) as $item) { $wallets[] = $user->createWallet([ - 'name' => 'index' . $item, + 'name' => 'index'.$item, ]); } diff --git a/tests/Units/Domain/ProductTest.php b/tests/Units/Domain/ProductTest.php index 83f5da746..894eabbc4 100644 --- a/tests/Units/Domain/ProductTest.php +++ b/tests/Units/Domain/ProductTest.php @@ -261,8 +261,7 @@ public function testPayCustomPrice(): void $cart = app(Cart::class) ->withItem($productIn, pricePerItem: 1_000) - ->withItem($productIn) - ; + ->withItem($productIn); self::assertSame(6_000 + (int) $buyer->getKey(), (int) $cart->getTotal($buyer)); diff --git a/tests/Units/Domain/StateTest.php b/tests/Units/Domain/StateTest.php index a06b80225..38a0f6508 100644 --- a/tests/Units/Domain/StateTest.php +++ b/tests/Units/Domain/StateTest.php @@ -4,6 +4,7 @@ namespace Bavix\Wallet\Test\Units\Domain; +use function app; use Bavix\Wallet\Internal\Service\DatabaseServiceInterface; use Bavix\Wallet\Models\Wallet; use Bavix\Wallet\Services\BookkeeperServiceInterface; @@ -11,7 +12,6 @@ use Bavix\Wallet\Test\Infra\Factories\BuyerFactory; use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\TestCase; -use function app; /** * @internal @@ -36,8 +36,7 @@ public function testForceUpdate(): void Wallet::whereKey($buyer->wallet->getKey()) ->update([ 'balance' => 10, - ]) - ; + ]); /** * Create a state when the cache is empty. For example, something went wrong and your database has incorrect diff --git a/tests/Units/Domain/TransactionsFilterTest.php b/tests/Units/Domain/TransactionsFilterTest.php index ec89317d5..54fd89294 100644 --- a/tests/Units/Domain/TransactionsFilterTest.php +++ b/tests/Units/Domain/TransactionsFilterTest.php @@ -38,20 +38,16 @@ public function testMetaAccount(): void $nullable = $buyer->transactions() ->whereNull('meta') - ->count() - ; + ->count(); $customers = $buyer->transactions() ->where('meta->account', 'customers') - ->count() - ; + ->count(); $expenses = $buyer->transactions() ->where('meta->account', 'expenses') - ->count() - ; + ->count(); $vendors = $buyer->transactions() ->where('meta->account', 'vendors') - ->count() - ; + ->count(); self::assertSame(1, $nullable); self::assertSame(1, $customers); @@ -61,8 +57,7 @@ public function testMetaAccount(): void $countByPeriods = $buyer->transactions() ->whereIn('meta->account', ['customers', 'expenses', 'vendors']) ->whereBetween('created_at', [now()->subDays(7), now()]) - ->count() - ; + ->count(); self::assertSame(3, $countByPeriods); } @@ -90,13 +85,11 @@ public function testTransferMeta(): void $credits1 = $buyer1->transactions() ->where('meta->type', 'credit') - ->count() - ; + ->count(); $credits2 = $buyer2->transactions() ->where('meta->type', 'credit') - ->count() - ; + ->count(); self::assertSame(1, $credits1); self::assertSame(1, $credits2); @@ -118,8 +111,7 @@ public function testPagination(): void $query = Transaction::with('wallet') ->where('payable_id', $buyer->getKey()) ->where('wallet_id', '=', $buyer->wallet->getKey()) - ->orderBy('created_at', 'desc') - ; + ->orderBy('created_at', 'desc'); $page1 = (clone $query)->paginate(10, page: 1); self::assertCount(10, $page1->items()); @@ -159,13 +151,11 @@ public function testPagination2(): void ->where('payable_type', '=', $buyer->getMorphClass()) ->where('payable_id', '=', $buyer->getKey()) ->where('wallet_id', '=', $buyer->wallet->getKey()) - ->join($walletTableName, $transactionTableName . '.wallet_id', '=', $walletTableName . '.id') - ->select($transactionTableName . '.*', $walletTableName . '.name') - ->get() - ; + ->join($walletTableName, $transactionTableName.'.wallet_id', '=', $walletTableName.'.id') + ->select($transactionTableName.'.*', $walletTableName.'.name') + ->get(); }) - ->orderBy('created_at', 'desc') - ; + ->orderBy('created_at', 'desc'); $page1 = (clone $query)->paginate(10, page: 1); self::assertCount(10, $page1->items()); diff --git a/tests/Units/Domain/WalletFloatTest.php b/tests/Units/Domain/WalletFloatTest.php index 6ba1f6199..b5df1a970 100644 --- a/tests/Units/Domain/WalletFloatTest.php +++ b/tests/Units/Domain/WalletFloatTest.php @@ -296,16 +296,16 @@ public function testBitcoin(): void // optimize app(DatabaseServiceInterface::class)->transaction(function () use ($user) { - for ($i = 0; $i < 256; ++$i) { + for ($i = 0; $i < 256; $i++) { $user->depositFloat('0.00000001'); // Satoshi } }); - self::assertSame($user->balance, '256' . str_repeat('0', 32 - 8)); + self::assertSame($user->balance, '256'.str_repeat('0', 32 - 8)); self::assertSame(0, $math->compare($user->balanceFloat, '0.00000256')); - $user->deposit(256 . str_repeat('0', 32)); - $user->depositFloat('0.' . str_repeat('0', 31) . '1'); + $user->deposit(256 .str_repeat('0', 32)); + $user->depositFloat('0.'.str_repeat('0', 31).'1'); [$q, $r] = explode('.', $user->balanceFloat, 2); self::assertSame(strlen($r), $user->wallet->decimal_places); diff --git a/tests/Units/Domain/WalletTest.php b/tests/Units/Domain/WalletTest.php index 5fa63da19..90e615d88 100644 --- a/tests/Units/Domain/WalletTest.php +++ b/tests/Units/Domain/WalletTest.php @@ -272,8 +272,7 @@ public function testRecalculate(): void $user->transactions() ->update([ 'confirmed' => true, - ]) - ; + ]); self::assertSame(0, $user->balanceInt); $user->wallet->refreshBalance(); @@ -311,7 +310,7 @@ public function testGetDynamicDefaultSlug(): void self::assertNotNull($user->deposit(100)); self::assertSame(100, $user->balanceInt); - self::assertSame('default-' . $user->email, $user->wallet->slug); + self::assertSame('default-'.$user->email, $user->wallet->slug); } public function testCrash(): void diff --git a/tests/Units/Service/DeferrableTest.php b/tests/Units/Service/DeferrableTest.php index a5ac73698..2860aea11 100644 --- a/tests/Units/Service/DeferrableTest.php +++ b/tests/Units/Service/DeferrableTest.php @@ -16,8 +16,7 @@ final class DeferrableTest extends TestCase public function testCheckDeferrableProvider(): void { $walletServiceProvider = app() - ->resolveProvider(WalletServiceProvider::class) - ; + ->resolveProvider(WalletServiceProvider::class); self::assertInstanceOf(DeferrableProvider::class, $walletServiceProvider); self::assertNotEmpty($walletServiceProvider->provides()); diff --git a/tests/Units/Service/LockServiceTest.php b/tests/Units/Service/LockServiceTest.php index 2413c5edf..4a0d2b05d 100644 --- a/tests/Units/Service/LockServiceTest.php +++ b/tests/Units/Service/LockServiceTest.php @@ -67,8 +67,8 @@ public function testLockDeep(): void public function testInTransactionLockable(): void { - $blockKey1 = __METHOD__ . '1'; - $blockKey2 = __METHOD__ . '2'; + $blockKey1 = __METHOD__.'1'; + $blockKey2 = __METHOD__.'2'; $lock = app(LockServiceInterface::class); self::assertFalse($lock->isBlocked($blockKey1)); self::assertFalse($lock->isBlocked($blockKey2)); diff --git a/tests/migrations/2014_10_12_000000_create_users_table.php b/tests/migrations/2014_10_12_000000_create_users_table.php index fe682a9fd..0c31be4be 100644 --- a/tests/migrations/2014_10_12_000000_create_users_table.php +++ b/tests/migrations/2014_10_12_000000_create_users_table.php @@ -6,7 +6,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create('users', static function (Blueprint $table) { diff --git a/tests/migrations/2018_11_08_214421_create_items_table.php b/tests/migrations/2018_11_08_214421_create_items_table.php index 291fc42ca..8639b4775 100644 --- a/tests/migrations/2018_11_08_214421_create_items_table.php +++ b/tests/migrations/2018_11_08_214421_create_items_table.php @@ -6,7 +6,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create('items', static function (Blueprint $table) { 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 6ba60f684..63a46f544 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 @@ -7,13 +7,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::table((new Transaction())->getTable(), static function (Blueprint $table) { $table->string('bank_method') - ->nullable() - ; + ->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 c5db216d3..11e2b3a34 100644 --- a/tests/migrations/2022_01_26_185311_create_managers_table.php +++ b/tests/migrations/2022_01_26_185311_create_managers_table.php @@ -6,13 +6,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ public function up(): void { Schema::create('managers', static function (Blueprint $table) { $table->uuid('id') - ->primary() - ; + ->primary(); $table->string('name'); $table->string('email'); $table->timestamps(); diff --git a/tests/migrations/2023_12_13_190445_create_cache_table.php b/tests/migrations/2023_12_13_190445_create_cache_table.php index 535685990..201ddd78d 100644 --- a/tests/migrations/2023_12_13_190445_create_cache_table.php +++ b/tests/migrations/2023_12_13_190445_create_cache_table.php @@ -6,7 +6,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class() extends Migration +{ /** * Run the migrations. */