File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ());
You can’t perform that action at this time.
0 commit comments