Skip to content

Commit

Permalink
updated readme image
Browse files Browse the repository at this point in the history
  • Loading branch information
SalihBorucu committed May 21, 2022
2 parents 1bb337d + 4ac9732 commit 848002c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/Casts/Currency.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php


namespace Kodeas\Currency\Casts;


use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
use Kodeas\Currency\Currency as CurrencyType;
use Kodeas\Currency\Exceptions\InvalidCurrencyFormatException;


class Currency implements CastsAttributes
{
/**
Expand All @@ -36,9 +33,10 @@ public function get($model, string $key, mixed $value, array $attributes): Curre
*/
public function set($model, string $key, mixed $value, array $attributes): int
{
if (!($value instanceof CurrencyType)) {
if (! ($value instanceof CurrencyType)) {
$currency = CurrencyType::class;
$type = getType($value);

throw new InvalidCurrencyFormatException("The given value must be $currency. $type was given.");
}

Expand Down
2 changes: 0 additions & 2 deletions src/Exceptions/InvalidCurrencyFormatException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Kodeas\Currency\Exceptions;


class InvalidCurrencyFormatException extends \Exception
{
}
4 changes: 1 addition & 3 deletions src/Models/TestModel.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Kodeas\Currency\Models;


use Illuminate\Database\Eloquent\Model;
use Kodeas\Currency\Casts\Currency;

Expand All @@ -12,6 +10,6 @@ class TestModel extends Model
protected $guarded = [];

protected $casts = [
'amount_with_cast' => Currency::class
'amount_with_cast' => Currency::class,
];
}
6 changes: 3 additions & 3 deletions tests/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$model = TestModel::make([
'amount_with_cast' => $amount,
'amount_without_cast' => 1
'amount_without_cast' => 1,
]);

expect($model->amount_with_cast)
Expand All @@ -29,7 +29,7 @@

$model = TestModel::make([
'amount_with_cast' => $amount,
'amount_without_cast' => 1
'amount_without_cast' => 1,
]);

expect($model->amount_with_cast)
Expand All @@ -47,6 +47,6 @@
it('throws type exception', function () {
$model = TestModel::make([
'amount_with_cast' => 1,
'amount_without_cast' => 1
'amount_without_cast' => 1,
]);
})->throws(InvalidCurrencyFormatException::class);
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Kodeas\Currency\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use Kodeas\Currency\CurrencyServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
{
Expand Down

0 comments on commit 848002c

Please sign in to comment.