Skip to content

Commit

Permalink
Merge pull request #1 from boring-dragon/master
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
aharen authored Dec 21, 2022
2 parents 1d675c6 + 2d91921 commit 3d0ccaa
Show file tree
Hide file tree
Showing 10 changed files with 8,337 additions and 94 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Aharen\\Tests\\MoneyTest::test_can_instantiate_a_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_add_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_subtract_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_add_other_money_objects_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_subtract_other_money_objects_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_multiply_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_instantiate_a_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_add_and_subtract_rufiyaa":4,"Aharen\\Tests\\MoneyTest::it_can_divide_rufiyaa":3,"Aharen\\Tests\\MoneyTest::it_can_multiply_other_money_objects":4,"Aharen\\Tests\\MoneyTest::it_can_divide_other_money_objects":4},"times":{"Aharen\\Tests\\MoneyTest::test_can_instantiate_a_rufiyaa":0.058,"Aharen\\Tests\\MoneyTest::it_can_instantiate_a_rufiyaa":0.059,"Aharen\\Tests\\MoneyTest::it_can_add_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_subtract_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_add_and_subtract_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_add_other_money_objects_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_subtract_other_money_objects_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_multiply_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_divide_rufiyaa":0.002,"Aharen\\Tests\\MoneyTest::it_can_add_other_money_objects":0.001,"Aharen\\Tests\\MoneyTest::it_can_subtract_other_money_objects":0.001,"Aharen\\Tests\\MoneyTest::it_can_multiply_other_money_objects":0.001,"Aharen\\Tests\\MoneyTest::it_can_divide_other_money_objects":0.001}}
103 changes: 92 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,133 @@ Simple class with Facade to handle money for Laravel 5. The class stores and cal

## Installation

composer require aharen/laravel-money
composer require aharen/laravel-money

## Configuration

1. Add `MoneyServiceProvider` to `providers` in `config/app.php`

aharen\Money\MoneyServiceProvider::class,
aharen\Money\MoneyServiceProvider::class,

2. Add `Money` Facade to `aliases` in `config/app.php`

Money => aharen\Money\MoneyManagerFacade::class,
Money => aharen\Money\MoneyManagerFacade::class,

## Usage

Initiate from either Rufiyaa
Initiate from either Rufiyaa

$money = Money::fromRufiyaa(10);
```php
$money = Money::fromRufiyaa(10);
```

or Laari

$money = Money::fromLaari(1000);
```php
$money = Money::fromLaari(1000);
```

### Addition

Expects the provided ammount to be added in Laari

$money->add(100);
```php
Money::fromRufiyaa(20)
->add(100) // 1 rufiyaa
->inRufiyaa();
```

Adding other money objects

```php
Money::fromRufiyaa(20)
->add(Money::fromRufiyaa(20.5))
->inRufiyaa();
```

### Subtraction

Expects the provided ammount to be subtracted in Laari

$money->subtract(100);
```php
Money::fromRufiyaa(20)
->subtract(100) // 1 rufiyaa
->inRufiyaa();
```

Subtracting other money objects

```php
Money::fromRufiyaa(20)
->subtract(Money::fromRufiyaa(5)
->inRufiyaa();
```

### Multiplication

Expects the provided ammount to be multiplied in Laari

```php
Money::fromRufiyaa(2)
->multiply(200) // 2 rufiyaa
->inRufiyaa();
```

Multiplying other money objects

```php
Money::fromRufiyaa(20)
->multiply(Money::fromRufiyaa(5))
->inRufiyaa();
```

### Division

Expects the provided ammount to be multiplied in Laari

```php
Money::fromRufiyaa(4)
->divide(200) // 2 rufiyaa
->inRufiyaa();
```

Dividing other money objects

```php
Money::fromRufiyaa(4)
->divide(Money::fromRufiyaa(2))
->inRufiyaa();
```

### Chaining Methods

You have the ability to manipulate the values in a chainable way.

```php
Money::fromRufiyaa(20)
->add(200) // 2 rufiyaa
->subtract(100) // 1 rufiyaa
->inRufiyaa();
```

### Output

There are 3 output options available:

1. Output in Laari

$money->inLaari();
```php
$money->inLaari();
```

2. Output in Rufiyaa

$money->inRufiyaa();
```php
$money->inRufiyaa();
```

3. Output in Rufiyaa and Laari

$money->inRufiyaaAndLaari();
```php
$money->inRufiyaaAndLaari();
```
17 changes: 15 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@
"name": "Ahmed Khusaam",
"email": "hello@khusaam.com"
}],
"require": {
"php": "^7.3|^8.0",
"illuminate/support": "^7.0|^8.0|^9.0"
},
"require-dev": {
"graham-campbell/testbench": "^5.7",
"phpunit/phpunit": "^8.5|^9.5.10"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"aharen\\": "src/"
"Aharen\\": "src/"
}
}
},
"autoload-dev": {
"psr-4": {
"Aharen\\Tests\\": "tests/"
}
}
}
Loading

0 comments on commit 3d0ccaa

Please sign in to comment.