Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Climactic/laravel-credits
Browse files Browse the repository at this point in the history
  • Loading branch information
adiologydev committed Nov 29, 2024
2 parents eff2d7f + f6230cb commit 6307ae6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

## v1.0.1 - 2024-11-21

- feat: `getBalanceAsOf` function now supports integer timestamps
- chore: remove unused config options (description length & required, decimal precision)
- chore: remove config values from migrations as they shouldn't be dynamic.
- chore: add typedocs for `HasCredits` trait.

## v1.0.0 - 2024-11-20

Initial Release with Core Functionality
28 changes: 1 addition & 27 deletions src/Traits/HasCredits.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public function creditTransactions(): MorphMany

/**
* Add credits to the model.
*
* @param float $amount
* @param string|null $description
* @param array $metadata
* @return Credit
*/
public function addCredits(float $amount, ?string $description = null, array $metadata = []): Credit
{
Expand Down Expand Up @@ -52,11 +47,6 @@ public function addCredits(float $amount, ?string $description = null, array $me

/**
* Deduct credits from the model.
*
* @param float $amount
* @param string|null $description
* @param array $metadata
* @return Credit
*/
public function deductCredits(float $amount, ?string $description = null, array $metadata = []): Credit
{
Expand Down Expand Up @@ -88,8 +78,6 @@ public function deductCredits(float $amount, ?string $description = null, array

/**
* Get the current balance of the model.
*
* @return float
*/
public function getCurrentBalance(): float
{
Expand All @@ -100,12 +88,6 @@ public function getCurrentBalance(): float

/**
* Transfer credits from the model to another model.
*
* @param self $recipient
* @param float $amount
* @param string|null $description
* @param array $metadata
* @return array
*/
public function transferCredits(self $recipient, float $amount, ?string $description = null, array $metadata = []): array
{
Expand Down Expand Up @@ -139,10 +121,6 @@ public function transferCredits(self $recipient, float $amount, ?string $descrip

/**
* Get the transaction history of the model.
*
* @param int $limit
* @param string $order
* @return Collection
*/
public function getTransactionHistory(int $limit = 10, string $order = 'desc'): Collection
{
Expand All @@ -154,9 +132,6 @@ public function getTransactionHistory(int $limit = 10, string $order = 'desc'):

/**
* Check if the model has enough credits.
*
* @param float $amount
* @return bool
*/
public function hasEnoughCredits(float $amount): bool
{
Expand All @@ -166,8 +141,7 @@ public function hasEnoughCredits(float $amount): bool
/**
* Get the balance of the model as of a specific date and time or timestamp.
*
* @param \DateTimeInterface|int $dateTime
* @return float
* @param \DateTimeInterface|int $dateTime
*/
public function getBalanceAsOf($dateTime): float
{
Expand Down
2 changes: 1 addition & 1 deletion tests/HasCreditsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$this->user->addCredits(100.00);

expect(fn() => $this->user->deductCredits(150.00))
expect(fn () => $this->user->deductCredits(150.00))
->toThrow(InsufficientCreditsException::class);
});

Expand Down
7 changes: 3 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Climactic\Credits\Tests;

use Climactic\Credits\CreditsServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
Expand Down Expand Up @@ -38,10 +37,10 @@ public function getEnvironmentSetUp($app)
protected function defineDatabaseMigrations()
{
// Include the package migrations
include_once __DIR__ . '/../database/migrations/create_credits_table.php.stub';
(include __DIR__ . '/../database/migrations/create_credits_table.php.stub')->up();
include_once __DIR__.'/../database/migrations/create_credits_table.php.stub';
(include __DIR__.'/../database/migrations/create_credits_table.php.stub')->up();

// Include the test migrations
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
}

0 comments on commit 6307ae6

Please # to comment.