1010
1111namespace Money ;
1212
13+ /**
14+ * Class Money
15+ * @package Money
16+ * @method static Money EUR(float $amount) Create a Money object with EUR currency.
17+ * @method static Money USD(float $amount) Create a Money object with USD currency.
18+ */
1319class Money
1420{
1521 const ROUND_HALF_UP = PHP_ROUND_HALF_UP ;
@@ -27,14 +33,14 @@ class Money
2733
2834 /**
2935 * Create a Money instance
30- * @param float $amount Amount
36+ * @param int| float $amount Amount
3137 * @param \Money\Currency $currency
3238 * @throws \Money\InvalidArgumentException
3339 */
3440 public function __construct ($ amount , Currency $ currency )
3541 {
36- if (!is_float ($ amount )) {
37- throw new InvalidArgumentException ("The first parameter of Money must be a float . " );
42+ if (!is_numeric ($ amount )) {
43+ throw new InvalidArgumentException ("The first parameter of Money must be numeric . " );
3844 }
3945 $ this ->amount = $ amount ;
4046 $ this ->currency = $ currency ;
@@ -49,7 +55,7 @@ public function __construct($amount, Currency $currency)
4955 */
5056 public static function __callStatic ($ method , $ arguments )
5157 {
52- return new Money ($ arguments [0 ], new Currency ($ method ));
58+ return new Money (( float ) $ arguments [0 ], new Currency ($ method ));
5359 }
5460
5561 /**
@@ -243,7 +249,7 @@ public function allocate(array $ratios)
243249 /** @return bool */
244250 public function isZero ()
245251 {
246- return $ this ->amount === 0 ;
252+ return $ this ->amount == 0 ;
247253 }
248254
249255 /** @return bool */
@@ -277,21 +283,6 @@ public static function stringToUnits( $string )
277283 return (int ) $ units ;
278284 }
279285
280- public function format ()
281- {
282- return '$ ' . number_format ($ this ->getAmount () / 100 , 2 );
283- }
284-
285- /**
286- * Convert into formatted amount (hardcoded to USD for the time being).
287- *
288- * @return string
289- */
290- public function __toString ()
291- {
292- return number_format ($ this ->getAmount () / 100 , 2 );
293- }
294-
295286 /**
296287 * Extracts a formatted money string.
297288 * @example echo Money::USD(500)->formattedString();
@@ -328,18 +319,13 @@ public function formattedString()
328319 return $ prefix . $ value . $ suffix ;
329320 }
330321
331- public function format ()
332- {
333- return '$ ' . number_format ($ this ->getAmount () / 100 , 2 );
334- }
335-
336322 /**
337323 * Convert into formatted amount (hardcoded to USD for the time being).
338324 *
339325 * @return string
340326 */
341327 public function __toString ()
342328 {
343- return number_format ( $ this ->getAmount () / 100 , 2 );
329+ return $ this ->formattedString ( );
344330 }
345331}
0 commit comments