Skip to content

Commit f8b5e1b

Browse files
author
Babichev Maxim
committed
micro optimize
1 parent d68c4a3 commit f8b5e1b

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/Traits/HasGift.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ public function gift(Wallet $to, Product $product, bool $force = null): Transfer
5757
$santa = $this;
5858

5959
/**
60-
* @return Transfer
60+
* Unfortunately,
61+
* I think it is wrong to make the "assemble" method public.
62+
* That's why I address him like this!
6163
*/
62-
$callback = function() use ($santa, $product, $force) {
64+
return DB::transaction(static function() use ($santa, $to, $product, $force) {
6365
$amount = $product->getAmountProduct();
6466
$meta = $product->getMetaProduct();
6567
$fee = app(WalletService::class)
@@ -79,7 +81,7 @@ public function gift(Wallet $to, Product $product, bool $force = null): Transfer
7981
$deposit = $commonService->deposit($product, $amount, $meta);
8082

8183
$from = app(WalletService::class)
82-
->getWallet($this);
84+
->getWallet($to);
8385

8486
$transfers = $commonService->assemble([
8587
(new Bring())
@@ -91,16 +93,7 @@ public function gift(Wallet $to, Product $product, bool $force = null): Transfer
9193
]);
9294

9395
return current($transfers);
94-
};
95-
96-
/**
97-
* Unfortunately,
98-
* I think it is wrong to make the "assemble" method public.
99-
* That's why I address him like this!
100-
*/
101-
return DB::transaction(
102-
$callback->bindTo($to, get_class($to))
103-
);
96+
});
10497
}
10598

10699
/**

0 commit comments

Comments
 (0)