Skip to content

Commit 52f954f

Browse files
committed
remove ProxyService.php
1 parent 45447b4 commit 52f954f

File tree

10 files changed

+23
-152
lines changed

10 files changed

+23
-152
lines changed

.phpstorm.meta.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Bavix\Wallet\Objects\Operation;
1515
use Bavix\Wallet\Services\CommonService;
1616
use Bavix\Wallet\Services\ExchangeService;
17-
use Bavix\Wallet\Services\ProxyService;
1817
use Bavix\Wallet\Services\WalletService;
1918

2019
override(\app(0), map([
@@ -24,7 +23,6 @@
2423
EmptyLock::class => EmptyLock::class,
2524
ExchangeService::class => ExchangeService::class,
2625
CommonService::class => CommonService::class,
27-
ProxyService::class => ProxyService::class,
2826
WalletService::class => WalletService::class,
2927
Wallet::class => Wallet::class,
3028
Transfer::class => Transfer::class,

config/config.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Bavix\Wallet\Objects\Operation;
77
use Bavix\Wallet\Services\ExchangeService;
88
use Bavix\Wallet\Services\CommonService;
9-
use Bavix\Wallet\Services\ProxyService;
109
use Bavix\Wallet\Services\WalletService;
1110
use Bavix\Wallet\Services\LockService;
1211
use Bavix\Wallet\Models\Transaction;
@@ -75,7 +74,6 @@
7574
'services' => [
7675
'exchange' => ExchangeService::class,
7776
'common' => CommonService::class,
78-
'proxy' => ProxyService::class,
7977
'wallet' => WalletService::class,
8078
'lock' => LockService::class,
8179
],

src/Commands/RefreshBalance.php

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

55
use Bavix\Wallet\Models\Wallet;
66
use Bavix\Wallet\Services\DbService;
7-
use Bavix\Wallet\Services\ProxyService;
87
use Illuminate\Console\Command;
98
use Illuminate\Database\Query\JoinClause;
109
use Illuminate\Database\SQLiteConnection;
@@ -37,7 +36,6 @@ class RefreshBalance extends Command
3736
*/
3837
public function handle(): void
3938
{
40-
app(ProxyService::class)->fresh();
4139
app(DbService::class)->transaction(function () {
4240
$wallet = config('wallet.wallet.table', 'wallets');
4341
app(DbService::class)

src/Services/ProxyService.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

src/Services/WalletService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ public function getWallet(Wallet $object, bool $autoSave = true): WalletModel
134134
public function refresh(WalletModel $wallet): bool
135135
{
136136
return app(LockService::class)->lock($this, __FUNCTION__, static function () use ($wallet) {
137+
$math = app(Mathable::class);
137138
app(Storable::class)->getBalance($wallet);
139+
$whatIs = $wallet->balance;
138140
$balance = $wallet->getAvailableBalance();
139141
$wallet->balance = $balance;
140142

141143
return app(Storable::class)->setBalance($wallet, $balance) &&
142-
$wallet->save();
144+
(!$math->compare($whatIs, $balance) || $wallet->save());
143145
});
144146
}
145147

src/WalletServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Bavix\Wallet\Services\ExchangeService;
1919
use Bavix\Wallet\Services\LockService;
2020
use Bavix\Wallet\Simple\Math;
21-
use Bavix\Wallet\Services\ProxyService;
2221
use Bavix\Wallet\Services\WalletService;
2322
use Bavix\Wallet\Simple\Rate;
2423
use Bavix\Wallet\Simple\Store;
@@ -93,7 +92,6 @@ public function register(): void
9392
$this->app->singleton(DbService::class, config('wallet.services.db', DbService::class));
9493
$this->app->singleton(ExchangeService::class, config('wallet.services.exchange', ExchangeService::class));
9594
$this->app->singleton(CommonService::class, config('wallet.services.common', CommonService::class));
96-
$this->app->singleton(ProxyService::class, config('wallet.services.proxy', ProxyService::class));
9795
$this->app->singleton(WalletService::class, config('wallet.services.wallet', WalletService::class));
9896
$this->app->singleton(LockService::class, config('wallet.services.lock', LockService::class));
9997

tests/BalanceTest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Bavix\Wallet\Interfaces\Storable;
66
use Bavix\Wallet\Models\Wallet;
77
use Bavix\Wallet\Services\CommonService;
8-
use Bavix\Wallet\Services\ProxyService;
9-
use Bavix\Wallet\Services\WalletService;
8+
use Bavix\Wallet\Simple\Store;
109
use Bavix\Wallet\Test\Models\Buyer;
1110
use Bavix\Wallet\Test\Models\UserMulti;
1211
use Illuminate\Support\Facades\DB;
@@ -224,7 +223,6 @@ public function testArtisanRefresh(): void
224223
}
225224

226225
// fresh balance
227-
app(ProxyService::class)->fresh();
228226
DB::table(config('wallet.wallet.table'))
229227
->update(['balance' => 0]);
230228

@@ -254,13 +252,30 @@ public function testForceUpdate(): void
254252
Wallet::whereKey($buyer->wallet->getKey())
255253
->update(['balance' => 10]);
256254

257-
app(ProxyService::class)->fresh();
255+
/**
256+
* Create a state when the cache is empty.
257+
* For example, something went wrong and your database has incorrect data.
258+
* Unfortunately, the library will work with what is.
259+
* But there is an opportunity to recount the balance.
260+
*
261+
* Here is an example:
262+
*/
263+
app()->singleton(Storable::class, Store::class);
264+
$this->assertEquals($wallet->getRawOriginal('balance'), 1000);
258265

266+
/**
267+
* We load the model from the base and our balance is 10.
268+
*/
259269
$wallet->refresh();
260270
$this->assertEquals($wallet->balance, 10);
271+
$this->assertEquals($wallet->getRawOriginal('balance'), 10);
261272

273+
/**
274+
* Now we fill the cache with relevant data (PS, the data inside the model will be updated).
275+
*/
262276
$wallet->refreshBalance();
263277
$this->assertEquals($wallet->balance, 1000);
278+
$this->assertEquals($wallet->getRawOriginal('balance'), 1000);
264279
}
265280

266281
}

tests/ProxyTest.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/SingletonTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Bavix\Wallet\Services\DbService;
1212
use Bavix\Wallet\Services\ExchangeService;
1313
use Bavix\Wallet\Services\LockService;
14-
use Bavix\Wallet\Services\ProxyService;
1514
use Bavix\Wallet\Services\WalletService;
1615
use Bavix\Wallet\Test\Common\Models\Transaction;
1716
use Bavix\Wallet\Test\Common\Models\Transfer;
@@ -109,14 +108,6 @@ public function testCommonService(): void
109108
$this->assertEquals($this->getRefId(CommonService::class), $this->getRefId(CommonService::class));
110109
}
111110

112-
/**
113-
* @return void
114-
*/
115-
public function testProxyService(): void
116-
{
117-
$this->assertEquals($this->getRefId(ProxyService::class), $this->getRefId(ProxyService::class));
118-
}
119-
120111
/**
121112
* @return void
122113
*/

tests/TestCase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Bavix\Wallet\Test;
44

5-
use Bavix\Wallet\Services\ProxyService;
5+
use Bavix\Wallet\Interfaces\Storable;
66
use Bavix\Wallet\Simple\BCMath;
77
use Bavix\Wallet\Simple\Math;
88
use Bavix\Wallet\Simple\Store;
@@ -24,7 +24,6 @@ class TestCase extends OrchestraTestCase
2424
*/
2525
public function setUp(): void
2626
{
27-
app(ProxyService::class)->fresh();
2827
parent::setUp();
2928
$this->withFactories(__DIR__ . '/factories');
3029
$this->loadMigrationsFrom([

0 commit comments

Comments
 (0)