diff --git a/src/Services/CreditService.php b/src/Services/CreditService.php index 8bdb048..19810ed 100644 --- a/src/Services/CreditService.php +++ b/src/Services/CreditService.php @@ -51,7 +51,7 @@ public function addCreditToHolder( 'meta' => $meta, ]); - if (!$expiresAt) { + if (! $expiresAt) { $credit = $this->addNonExpiringCredit( $holder, $amount, @@ -87,7 +87,7 @@ public function addNonExpiringCredit( ->lockForUpdate() ->first(); - if (!$credit) { + if (! $credit) { $credit = $this->creditModel->newInstance([ 'holder_type' => $holder->getMorphClass(), 'holder_id' => $holder->getKey(), @@ -116,7 +116,7 @@ public function addExpiringCredit( ]); } - public function useCredit( + public function useCreditFromHolder( Model $holder, float $amount, string $name, @@ -124,7 +124,7 @@ public function useCredit( ?array $meta = null, ) { - if (!$this->checkHolderCredit($holder, $amount)) { + if (! $this->checkHolderCredit($holder, $amount)) { throw new \Exception('Insufficient credit'); } @@ -141,7 +141,7 @@ public function useCredit( 'meta' => $meta, ]); - $credits = $this->getRemainingCreditByHolderForUpdate($holder); + $credits = $this->getRemainingCreditFromHolderForUpdate($holder); $remainingAmount = $amount; @@ -192,7 +192,10 @@ public function useCredit( } } - public function getRemainingCreditByHolderForUpdate( + /** + * @return \Illuminate\Support\Collection + */ + public function getRemainingCreditFromHolderForUpdate( Model $holder, ): Collection { return $this->creditModel