Skip to content

Commit f59eaf4

Browse files
authored
Merge pull request #107 from bavix/extends
#106 Extends
2 parents a95bd17 + 349c82b commit f59eaf4

22 files changed

+120
-52
lines changed

.phpstorm.meta.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use Bavix\Wallet\Services\ExchangeService;
1111
use Bavix\Wallet\Services\ProxyService;
1212
use Bavix\Wallet\Services\WalletService;
13+
use Bavix\Wallet\Services\MakeService;
1314

1415
override(\app(0), map([
16+
MakeService::class => MakeService::class,
1517
ExchangeService::class => ExchangeService::class,
1618
CommonService::class => CommonService::class,
1719
ProxyService::class => ProxyService::class,

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [3.3.0] - 2019-09-10
10+
### Added
11+
- Added the ability to easily overload the main classes #106
12+
913
## [3.2.1] - 2019-09-10
1014
### Fixed
1115
- Fixed calculation of commission for exchange #101 @haojingliu
@@ -399,7 +403,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
399403
- Exceptions: AmountInvalid, BalanceIsEmpty.
400404
- Models: Transfer, Transaction.
401405

402-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.2.1...HEAD
406+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.3.0...HEAD
407+
[3.3.0]: https://github.com/bavix/laravel-wallet/compare/3.2.1...3.3.0
403408
[3.2.1]: https://github.com/bavix/laravel-wallet/compare/3.2.0...3.2.1
404409
[3.2.0]: https://github.com/bavix/laravel-wallet/compare/3.1.6...3.2.0
405410
[3.1.6]: https://github.com/bavix/laravel-wallet/compare/3.1.5...3.1.6

config/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Bavix\Wallet\Services\ExchangeService;
44
use Bavix\Wallet\Services\CommonService;
5+
use Bavix\Wallet\Services\MakeService;
56
use Bavix\Wallet\Services\ProxyService;
67
use Bavix\Wallet\Services\WalletService;
78
use Bavix\Wallet\Services\LockService;
@@ -49,6 +50,7 @@
4950
'proxy' => ProxyService::class,
5051
'wallet' => WalletService::class,
5152
'lock' => LockService::class,
53+
'make' => MakeService::class,
5254
],
5355

5456
/**

src/Commands/RefreshBalance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Class RefreshBalance
1515
* @package Bavix\Wallet\Commands
16-
* @codeCoverageIgnore
16+
* @codeCoverageIgnore
1717
*/
1818
class RefreshBalance extends Command
1919
{

src/Objects/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Cart implements Countable
2525

2626
/**
2727
* @return static
28+
* @deprecated use app(MakeService::class)->makeCart()
2829
*/
2930
public static function make(): self
3031
{

src/Objects/EmptyLock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class EmptyLock implements Lock
1616
/**
1717
* Attempt to acquire the lock.
1818
*
19-
* @param callable|null $callback
19+
* @param callable|null $callback
2020
* @return mixed
2121
*/
2222
public function get($callback = null)
@@ -31,8 +31,8 @@ public function get($callback = null)
3131
/**
3232
* Attempt to acquire the lock for the given number of seconds.
3333
*
34-
* @param int $seconds
35-
* @param callable|null $callback
34+
* @param int $seconds
35+
* @param callable|null $callback
3636
* @return bool
3737
*/
3838
public function block($seconds, $callback = null): bool

src/Services/CommonService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Bavix\Wallet\Models\Transfer;
1010
use Bavix\Wallet\Models\Wallet as WalletModel;
1111
use Bavix\Wallet\Objects\Bring;
12-
use Bavix\Wallet\Objects\Operation;
1312
use Bavix\Wallet\Traits\HasWallet;
1413
use Illuminate\Support\Facades\DB;
1514
use function app;
@@ -53,7 +52,8 @@ public function forceTransfer(Wallet $from, Wallet $to, int $amount, ?array $met
5352
->getWallet($from);
5453

5554
$transfers = $this->multiBrings([
56-
(new Bring())
55+
app(MakeService::class)
56+
->makeBring()
5757
->setStatus($status)
5858
->setDeposit($deposit)
5959
->setWithdraw($withdraw)
@@ -84,7 +84,8 @@ public function forceWithdraw(Wallet $wallet, int $amount, ?array $meta, bool $c
8484
$wallet = $walletService->getWallet($wallet);
8585

8686
$transactions = $this->multiOperation($wallet, [
87-
(new Operation())
87+
app(MakeService::class)
88+
->makeOperation()
8889
->setType(Transaction::TYPE_WITHDRAW)
8990
->setConfirmed($confirmed)
9091
->setAmount(-$amount)
@@ -114,7 +115,8 @@ public function deposit(Wallet $wallet, int $amount, ?array $meta, bool $confirm
114115
$wallet = $walletService->getWallet($wallet);
115116

116117
$transactions = $this->multiOperation($wallet, [
117-
(new Operation())
118+
app(MakeService::class)
119+
->makeOperation()
118120
->setType(Transaction::TYPE_DEPOSIT)
119121
->setConfirmed($confirmed)
120122
->setAmount($amount)

src/Services/LockService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Bavix\Wallet\Services;
44

5-
use Bavix\Wallet\Objects\EmptyLock;
65
use Illuminate\Contracts\Cache\Lock;
76
use Illuminate\Contracts\Cache\LockProvider;
87
use Illuminate\Contracts\Cache\Store;
@@ -34,7 +33,7 @@ public function __construct()
3433
*/
3534
public function lock($self, string $name, \Closure $closure)
3635
{
37-
return $this->lockProvider($self, $name, (int) config('wallet.lock.seconds'))
36+
return $this->lockProvider($self, $name, (int)config('wallet.lock.seconds'))
3837
->get($this->bindTo($self, $closure));
3938
}
4039

@@ -88,7 +87,8 @@ protected function lockProvider($self, string $name, int $seconds): Lock
8887
}
8988
// @codeCoverageIgnoreEnd
9089

91-
return new EmptyLock();
90+
return app(MakeService::class)
91+
->makeEmptyLock();
9292
}
9393

9494
}

src/Services/MakeService.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Bavix\Wallet\Services;
4+
5+
use Bavix\Wallet\Objects\Bring;
6+
use Bavix\Wallet\Objects\Cart;
7+
use Bavix\Wallet\Objects\EmptyLock;
8+
use Bavix\Wallet\Objects\Operation;
9+
10+
class MakeService
11+
{
12+
13+
/**
14+
* @return Bring
15+
*/
16+
public function makeBring(): Bring
17+
{
18+
return new Bring();
19+
}
20+
21+
public function makeCart(): Cart
22+
{
23+
return new Cart();
24+
}
25+
26+
/**
27+
* @return EmptyLock
28+
*/
29+
public function makeEmptyLock(): EmptyLock
30+
{
31+
return new EmptyLock();
32+
}
33+
34+
/**
35+
* @return Operation
36+
*/
37+
public function makeOperation(): Operation
38+
{
39+
return new Operation();
40+
}
41+
42+
}

src/Services/WalletService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function fee(Wallet $wallet, int $amount): int
3434
{
3535
$fee = 0;
3636
if ($wallet instanceof Taxable) {
37-
$fee = (int) ($amount * $wallet->getFeePercent() / 100);
37+
$fee = (int)($amount * $wallet->getFeePercent() / 100);
3838
}
3939

4040
/**
@@ -100,7 +100,7 @@ public function getBalance(Wallet $object): int
100100
$wallet = $this->getWallet($object);
101101
$proxy = app(ProxyService::class);
102102
if (!$proxy->has($wallet->getKey())) {
103-
$proxy->set($wallet->getKey(), (int) $wallet->getOriginal('balance', 0));
103+
$proxy->set($wallet->getKey(), (int)$wallet->getOriginal('balance', 0));
104104
}
105105

106106
return $proxy[$wallet->getKey()];

0 commit comments

Comments
 (0)