Skip to content

Commit 01e5313

Browse files
committed
Add not integer support amount to Money VO
1 parent 6e82aa1 commit 01e5313

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Money/Money.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Money
1919
/**
2020
* Amount
2121
*
22-
* @var int
22+
* @var float
2323
*/
24-
private int $amount;
24+
private float $amount;
2525
/**
2626
* Currency
2727
*
@@ -30,10 +30,10 @@ class Money
3030
private Currency $currency;
3131

3232
/**
33-
* @param int $amount
33+
* @param float $amount
3434
* @param Currency $currency
3535
*/
36-
public function __construct(int $amount, Currency $currency)
36+
public function __construct(float $amount, Currency $currency)
3737
{
3838
$this->amount = $amount;
3939
$this->currency = $currency;
@@ -43,20 +43,20 @@ public function __construct(int $amount, Currency $currency)
4343
* Add an integer quantity to the amount and returns a new Money object.
4444
* Use a negative quantity for subtraction.
4545
*
46-
* @param int $quantity quantity to add
46+
* @param float $quantity quantity to add
4747
*
4848
* @return Money
4949
*/
50-
public function add(int $quantity): Money
50+
public function add(float $quantity): Money
5151
{
5252
$amount = $this->getAmount() + $quantity;
5353
return new static($amount, $this->getCurrency());
5454
}
5555

5656
/**
57-
* @return int
57+
* @return float
5858
*/
59-
public function getAmount(): int
59+
public function getAmount(): float
6060
{
6161
return $this->amount;
6262
}

tests/Money/MoneyTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public function testSuccess(): void
2222
self::assertEquals($currency, $money->getCurrency());
2323
}
2424

25+
public function testNotInteger(): void
26+
{
27+
$money = new Money($amount = 100.66, $currency = $this->createCurrency());
28+
29+
self::assertEquals($amount, $money->getAmount());
30+
self::assertEquals($currency, $money->getCurrency());
31+
}
32+
2533
public function testToString(): void
2634
{
2735
$money = new Money($amount = 100, $currency = $this->createCurrency());

0 commit comments

Comments
 (0)