@@ -9,12 +9,12 @@ class Money
99 /**
1010 * @var int
1111 */
12- private $ amount ;
12+ protected $ amount ;
1313
1414 /**
1515 * @var Currency
1616 */
17- private $ currency ;
17+ protected $ currency ;
1818
1919 /**
2020 * @param int $amount
@@ -52,18 +52,18 @@ public function equals(self $other): bool
5252 }
5353
5454 /**
55- * @return self
55+ * @return Money
5656 */
57- public function duplicate (): self
57+ public function duplicate ()
5858 {
59- return new self ($ this ->amount (), $ this ->currency ());
59+ return new static ($ this ->amount (), $ this ->currency ());
6060 }
6161
6262 /**
6363 * @param self $other
64- * @return self
64+ * @return Money
6565 */
66- public function add (self $ other ): self
66+ public function add (self $ other ): Money
6767 {
6868 if (!$ this ->currency ()->equals ($ other ->currency ())) {
6969 throw new InvalidArgumentException (
@@ -75,7 +75,7 @@ public function add(self $other): self
7575 );
7676 }
7777
78- return new self ($ this ->amount () + $ other ->amount (), $ this ->currency ());
78+ return new static ($ this ->amount () + $ other ->amount (), $ this ->currency ());
7979 }
8080
8181 /**
@@ -94,7 +94,7 @@ public function sub(self $other): self
9494 );
9595 }
9696
97- return new self ($ this ->amount () - $ other ->amount (), $ this ->currency ());
97+ return new static ($ this ->amount () - $ other ->amount (), $ this ->currency ());
9898 }
9999
100100 /**
@@ -103,7 +103,7 @@ public function sub(self $other): self
103103 */
104104 public function multiply (float $ multiplier ): self
105105 {
106- return new self (intval (floor ($ this ->amount () * $ multiplier )), $ this ->currency ());
106+ return new static (intval (floor ($ this ->amount () * $ multiplier )), $ this ->currency ());
107107 }
108108
109109 /**
@@ -121,7 +121,7 @@ public function increaseAmountBy(int $amount): self
121121 );
122122 }
123123
124- return new self ($ this ->amount () + $ amount , $ this ->currency ());
124+ return new static ($ this ->amount () + $ amount , $ this ->currency ());
125125 }
126126
127127 /**
@@ -139,6 +139,6 @@ public function decreaseAmountBy(int $amount): self
139139 );
140140 }
141141
142- return new self ($ this ->amount () - $ amount , $ this ->currency ());
142+ return new static ($ this ->amount () - $ amount , $ this ->currency ());
143143 }
144144}
0 commit comments