Skip to content

Commit 8f57694

Browse files
authored
Merge pull request #865 from bavix/864-can-a-new-field-be-added-to-the-transfer-table
[11.x] Adding an Extra column to the transfer table
2 parents 7a0f9c6 + 12151a7 commit 8f57694

27 files changed

+227
-22
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Bavix\Wallet\Models\Transfer;
6+
use Illuminate\Database\Migrations\Migration;
7+
use Illuminate\Database\Schema\Blueprint;
8+
use Illuminate\Support\Facades\Schema;
9+
10+
return new class() extends Migration {
11+
public function up(): void
12+
{
13+
Schema::table($this->table(), static function (Blueprint $table) {
14+
$table->json('extra')
15+
->nullable()
16+
->after('fee')
17+
;
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::dropColumns($this->table(), ['extra']);
24+
}
25+
26+
private function table(): string
27+
{
28+
return (new Transfer())->getTable();
29+
}
30+
};

phpstan.src.baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Constructor in Bavix\\\\Wallet\\\\External\\\\Dto\\\\Extra has parameter \\$extra with default value\\.$#"
5+
count: 1
6+
path: src/External/Dto/Extra.php
7+
38
-
49
message: "#^Constructor in Bavix\\\\Wallet\\\\External\\\\Dto\\\\Extra has parameter \\$uuid with default value\\.$#"
510
count: 1

src/External/Contracts/ExtraDtoInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ public function getDepositOption(): OptionDtoInterface;
1111
public function getWithdrawOption(): OptionDtoInterface;
1212

1313
public function getUuid(): ?string;
14+
15+
/**
16+
* @return array<mixed>|null
17+
*/
18+
public function getExtra(): ?array;
1419
}

src/External/Dto/Extra.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ final class Extra implements ExtraDtoInterface
1616
/**
1717
* @param OptionDtoInterface|array<mixed>|null $deposit
1818
* @param OptionDtoInterface|array<mixed>|null $withdraw
19+
* @param array<mixed>|null $extra
1920
*/
2021
public function __construct(
2122
OptionDtoInterface|array|null $deposit,
2223
OptionDtoInterface|array|null $withdraw,
23-
private readonly ?string $uuid = null
24+
private readonly ?string $uuid = null,
25+
private readonly ?array $extra = null
2426
) {
2527
$this->deposit = $deposit instanceof OptionDtoInterface ? $deposit : new Option($deposit);
2628
$this->withdraw = $withdraw instanceof OptionDtoInterface ? $withdraw : new Option($withdraw);
@@ -40,4 +42,12 @@ public function getUuid(): ?string
4042
{
4143
return $this->uuid;
4244
}
45+
46+
/**
47+
* @return array<mixed>|null
48+
*/
49+
public function getExtra(): ?array
50+
{
51+
return $this->extra;
52+
}
4353
}

src/Internal/Assembler/TransferDtoAssembler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(
1818
) {
1919
}
2020

21+
/** @param array<mixed>|null $extra */
2122
public function create(
2223
int $depositId,
2324
int $withdrawId,
@@ -26,7 +27,8 @@ public function create(
2627
Model $toModel,
2728
int $discount,
2829
string $fee,
29-
?string $uuid
30+
?string $uuid,
31+
?array $extra,
3032
): TransferDtoInterface {
3133
return new TransferDto(
3234
$uuid ?? $this->uuidService->uuid4(),
@@ -37,6 +39,7 @@ public function create(
3739
$toModel->getKey(),
3840
$discount,
3941
$fee,
42+
$extra,
4043
$this->clockService->now(),
4144
$this->clockService->now(),
4245
);

src/Internal/Assembler/TransferDtoAssemblerInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
interface TransferDtoAssemblerInterface
1111
{
12+
/** @param array<mixed>|null $extra */
1213
public function create(
1314
int $depositId,
1415
int $withdrawId,
@@ -17,6 +18,7 @@ public function create(
1718
Model $toModel,
1819
int $discount,
1920
string $fee,
20-
?string $uuid
21+
?string $uuid,
22+
?array $extra,
2123
): TransferDtoInterface;
2224
}

src/Internal/Assembler/TransferLazyDtoAssembler.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
final class TransferLazyDtoAssembler implements TransferLazyDtoAssemblerInterface
1313
{
14+
/** @param array<mixed>|null $extra */
1415
public function create(
1516
Wallet $fromWallet,
1617
Wallet $toWallet,
@@ -19,8 +20,19 @@ public function create(
1920
TransactionDtoInterface $withdrawDto,
2021
TransactionDtoInterface $depositDto,
2122
string $status,
22-
?string $uuid
23+
?string $uuid,
24+
?array $extra,
2325
): TransferLazyDtoInterface {
24-
return new TransferLazyDto($fromWallet, $toWallet, $discount, $fee, $withdrawDto, $depositDto, $status, $uuid);
26+
return new TransferLazyDto(
27+
$fromWallet,
28+
$toWallet,
29+
$discount,
30+
$fee,
31+
$withdrawDto,
32+
$depositDto,
33+
$status,
34+
$uuid,
35+
$extra,
36+
);
2537
}
2638
}

src/Internal/Assembler/TransferLazyDtoAssemblerInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
interface TransferLazyDtoAssemblerInterface
1212
{
13+
/** @param array<mixed>|null $extra */
1314
public function create(
1415
Wallet $fromWallet,
1516
Wallet $toWallet,
@@ -18,6 +19,7 @@ public function create(
1819
TransactionDtoInterface $withdrawDto,
1920
TransactionDtoInterface $depositDto,
2021
string $status,
21-
?string $uuid
22+
?string $uuid,
23+
?array $extra,
2224
): TransferLazyDtoInterface;
2325
}

src/Internal/Dto/BasketDto.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
/**
1313
* @param non-empty-array<int|string, ItemDtoInterface> $items
1414
* @param array<mixed> $meta
15+
* @param array<mixed>|null $extra
1516
*/
1617
public function __construct(
1718
private array $items,
18-
private array $meta
19+
private array $meta,
20+
private ?array $extra,
1921
) {
2022
}
2123

@@ -53,4 +55,12 @@ public function items(): array
5355
{
5456
return $this->items;
5557
}
58+
59+
/**
60+
* @return array<mixed>|null
61+
*/
62+
public function extra(): ?array
63+
{
64+
return $this->extra;
65+
}
5666
}

src/Internal/Dto/BasketDtoInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public function total(): int;
1717
*/
1818
public function meta(): array;
1919

20+
/**
21+
* @return array<mixed>|null
22+
*/
23+
public function extra(): ?array;
24+
2025
/**
2126
* @return non-empty-array<int|string, ItemDtoInterface>
2227
*/

0 commit comments

Comments
 (0)