Skip to content

Commit

Permalink
Updated the comments of several methods and improved some methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mreduar committed Sep 27, 2021
1 parent 1185e8a commit 514de43
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

All notable changes to `laravel-balance` will be documented in this file

## 1.3.0 - 2021-09-27

- Updated the comments of several methods and improved some methods params.

## 1.2.0 - 2021-05-26

- Changed name of reference to referenceable method to avoid null properties when eager loading
- Changed name of reference to referenceable method to avoid null properties when eager loading.

## 1.1.1 - 2021-05-26

Expand Down
34 changes: 22 additions & 12 deletions src/HasBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ public function getBalanceAttribute()
return $this->balanceHistory()->sum('amount') / 100;
}

/**
* Get the model's balance amount.
*
* @return int
*/
public function getIntBalanceAttribute()
{
return (int) $this->balanceHistory()->sum('amount');
}

/**
* Increase the balance amount.
*
* @param int $amount
* @param array $parameters
* @return bool
* @return \MrEduar\Balance\Balance
*/
public function increaseBalance(int $amount, array $parameters = [])
{
Expand All @@ -33,7 +43,7 @@ public function increaseBalance(int $amount, array $parameters = [])
*
* @param int $amount
* @param array $parameters
* @return bool
* @return \MrEduar\Balance\Balance
*/
public function decreaseBalance(int $amount, array $parameters = [])
{
Expand All @@ -45,7 +55,7 @@ public function decreaseBalance(int $amount, array $parameters = [])
*
* @param int $amount
* @param array $parameters
* @return bool
* @return \MrEduar\Balance\Balance
*/
public function modifyBalance(int $amount, array $parameters = [])
{
Expand All @@ -57,9 +67,9 @@ public function modifyBalance(int $amount, array $parameters = [])
*
* @param int|null $newAmount
* @param array $parameters
* @return bool
* @return \MrEduar\Balance\Balance
*/
public function resetBalance($newAmount = null, $parameters = [])
public function resetBalance(int $newAmount = null, $parameters = [])
{
$this->balanceHistory()->delete();

Expand All @@ -73,12 +83,12 @@ public function resetBalance($newAmount = null, $parameters = [])
/**
* Check if there is a positive balance.
*
* @param float $amount
* @param int $amount
* @return bool
*/
public function hasBalance($amount = 1)
public function hasBalance(int $amount = 1)
{
return $this->balance > 0 && $this->balance >= $amount;
return $this->balance > 0 && $this->balanceHistory()->sum('amount') >= $amount;
}

/**
Expand All @@ -96,9 +106,9 @@ public function hasNoBalance()
*
* @param int $amount
* @param array $parameters
* @return bool
* @return \MrEduar\Balance\Balance
*/
protected function createBalanceHistory($amount, array $parameters = [])
protected function createBalanceHistory(int $amount, array $parameters = [])
{
$reference = Arr::get($parameters, 'reference');

Expand All @@ -115,9 +125,9 @@ protected function createBalanceHistory($amount, array $parameters = [])
}

/**
* Relation with Balance.
* Get all Balance History.
*
* @return \Illuminate\Database\Eloquent\Relations\morphMany
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function balanceHistory()
{
Expand Down

0 comments on commit 514de43

Please sign in to comment.