Skip to content

Commit 28666e3

Browse files
committed
add model interfaces
1 parent 912b632 commit 28666e3

File tree

6 files changed

+97
-16
lines changed

6 files changed

+97
-16
lines changed

src/Models/Transaction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
* @property Wallet $payable
3030
* @property WalletModel $wallet
3131
*/
32-
class Transaction extends Model
32+
class Transaction extends Model implements TransactionInterface
3333
{
34-
public const TYPE_DEPOSIT = 'deposit';
35-
public const TYPE_WITHDRAW = 'withdraw';
36-
3734
/**
3835
* @var string[]
3936
*/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Models;
6+
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\MorphTo;
9+
10+
interface TransactionInterface
11+
{
12+
public const TYPE_DEPOSIT = 'deposit';
13+
public const TYPE_WITHDRAW = 'withdraw';
14+
15+
public function getTable(): string;
16+
17+
public function payable(): MorphTo;
18+
19+
public function wallet(): BelongsTo;
20+
21+
public function getAmountIntAttribute(): int;
22+
23+
public function getAmountFloatAttribute(): string;
24+
25+
/**
26+
* @param float|int|string $amount
27+
*/
28+
public function setAmountFloatAttribute($amount): void;
29+
}

src/Models/Transfer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@
2525
* @property Transaction $deposit
2626
* @property Transaction $withdraw
2727
*/
28-
class Transfer extends Model
28+
class Transfer extends Model implements TransferInterface
2929
{
30-
public const STATUS_EXCHANGE = 'exchange';
31-
public const STATUS_TRANSFER = 'transfer';
32-
public const STATUS_PAID = 'paid';
33-
public const STATUS_REFUND = 'refund';
34-
public const STATUS_GIFT = 'gift';
35-
3630
/**
3731
* @var string[]
3832
*/

src/Models/TransferInterface.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Models;
6+
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\MorphTo;
9+
10+
interface TransferInterface
11+
{
12+
public const STATUS_EXCHANGE = 'exchange';
13+
public const STATUS_TRANSFER = 'transfer';
14+
public const STATUS_PAID = 'paid';
15+
public const STATUS_REFUND = 'refund';
16+
public const STATUS_GIFT = 'gift';
17+
18+
public function getTable(): string;
19+
20+
public function from(): MorphTo;
21+
22+
public function to(): MorphTo;
23+
24+
public function deposit(): BelongsTo;
25+
26+
public function withdraw(): BelongsTo;
27+
}

src/Models/Wallet.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
use function app;
88
use function array_key_exists;
9-
use Bavix\Wallet\Interfaces\Confirmable;
10-
use Bavix\Wallet\Interfaces\Customer;
11-
use Bavix\Wallet\Interfaces\Exchangeable;
12-
use Bavix\Wallet\Interfaces\WalletFloat;
139
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
1410
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
1511
use Bavix\Wallet\Services\WalletServiceLegacy;
@@ -36,7 +32,7 @@
3632
* @property \Bavix\Wallet\Interfaces\Wallet $holder
3733
* @property string $currency
3834
*/
39-
class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchangeable
35+
class Wallet extends Model implements WalletInterface
4036
{
4137
use CanConfirm;
4238
use CanExchange;

src/Models/WalletInterface.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Models;
6+
7+
use Bavix\Wallet\Interfaces\Confirmable;
8+
use Bavix\Wallet\Interfaces\Customer;
9+
use Bavix\Wallet\Interfaces\Exchangeable;
10+
use Bavix\Wallet\Interfaces\WalletFloat;
11+
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
12+
use Illuminate\Database\Eloquent\Relations\MorphTo;
13+
14+
interface WalletInterface extends Customer, WalletFloat, Confirmable, Exchangeable
15+
{
16+
public function getTable(): string;
17+
18+
public function setNameAttribute(string $name): void;
19+
20+
/**
21+
* Under ideal conditions, you will never need a method.
22+
* Needed to deal with out-of-sync.
23+
*
24+
* @throws ExceptionInterface
25+
*/
26+
public function refreshBalance(): bool;
27+
28+
public function getOriginalBalance(): string;
29+
30+
/**
31+
* @return float|int
32+
*/
33+
public function getAvailableBalance();
34+
35+
public function holder(): MorphTo;
36+
37+
public function getCurrencyAttribute(): string;
38+
}

0 commit comments

Comments
 (0)