Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
package
money
Commits
cb1150bf
Commit
cb1150bf
authored
Apr 13, 2013
by
Mathias Verraes
Browse files
Docblocks cleanup
parent
a7efa509
Changes
9
Hide whitespace changes
Inline
Side-by-side
lib/Money/Currency.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
@@ -15,8 +15,13 @@ class Currency
/** @var string */
private
$name
;
/** @var array */
private
static
$currencies
;
/**
* @param string $name
* @throws UnknownCurrencyException
*/
public
function
__construct
(
$name
)
{
if
(
!
isset
(
static
::
$currencies
))
{
...
...
@@ -39,6 +44,7 @@ class Currency
}
/**
* @param \Money\Currency $other
* @return bool
*/
public
function
equals
(
Currency
$other
)
...
...
lib/Money/CurrencyPair.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
@@ -22,6 +22,12 @@ class CurrencyPair
/** @var float */
private
$ratio
;
/**
* @param \Money\Currency $counterCurrency
* @param \Money\Currency $baseCurrency
* @param float $ratio
* @throws \Money\InvalidArgumentException
*/
public
function
__construct
(
Currency
$counterCurrency
,
Currency
$baseCurrency
,
$ratio
)
{
if
(
!
is_numeric
(
$ratio
))
{
...
...
@@ -34,8 +40,9 @@ class CurrencyPair
}
/**
* @param string $iso String representation of the form "EUR/USD 1.2500"
* @return CurrencyPair
* @param string $iso String representation of the form "EUR/USD 1.2500"
* @throws \Exception
* @return \Money\CurrencyPair
*/
public
static
function
createFromIso
(
$iso
)
{
...
...
@@ -52,7 +59,11 @@ class CurrencyPair
return
new
static
(
new
Currency
(
$matches
[
1
]),
new
Currency
(
$matches
[
2
]),
$matches
[
3
]);
}
/** @return Money */
/**
* @param \Money\Money $money
* @throws InvalidArgumentException
* @return \Money\Money
*/
public
function
convert
(
Money
$money
)
{
if
(
!
$money
->
getCurrency
()
->
equals
(
$this
->
counterCurrency
))
{
...
...
@@ -63,13 +74,13 @@ class CurrencyPair
return
new
Money
((
int
)
round
(
$money
->
getAmount
()
*
$this
->
ratio
),
$this
->
baseCurrency
);
}
/** @return Currency */
/** @return
\Money\
Currency */
public
function
getCounterCurrency
()
{
return
$this
->
counterCurrency
;
}
/** @return Currency */
/** @return
\Money\
Currency */
public
function
getBaseCurrency
()
{
return
$this
->
baseCurrency
;
...
...
lib/Money/Exception.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
lib/Money/InvalidArgumentException.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
lib/Money/Money.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
@@ -22,14 +22,14 @@ class Money
*/
private
$amount
;
/** @var Money\Currency */
/** @var
\
Money\Currency */
private
$currency
;
/**
* Create a Money instance
* @param integer
$amount Amount, expressed in the smallest units of $currency (eg cents)
* @param Money\Currency
$currency
* @throws Money\InvalidArgumentException
* @param integer $amount Amount, expressed in the smallest units of $currency (eg cents)
* @param
\
Money\Currency $currency
* @throws
\
Money\InvalidArgumentException
*/
public
function
__construct
(
$amount
,
Currency
$currency
)
{
...
...
@@ -43,21 +43,26 @@ class Money
/**
* Convenience factory method for a Money object
* @example $fiveDollar = Money::USD(500);
* @return Money
* @param string $method
* @param array $arguments
* @return \Money\Money
*/
public
static
function
__callStatic
(
$method
,
$arguments
)
{
return
new
Money
(
$arguments
[
0
],
new
Currency
(
$method
));
}
/** @return bool */
/**
* @param \Money\Money $other
* @return bool
*/
public
function
isSameCurrency
(
Money
$other
)
{
return
$this
->
currency
->
equals
(
$other
->
currency
);
}
/**
* @throws Money\InvalidArgumentException
* @throws
\
Money\InvalidArgumentException
*/
private
function
assertSameCurrency
(
Money
$other
)
{
...
...
@@ -66,6 +71,10 @@ class Money
}
}
/**
* @param \Money\Money $other
* @return bool
*/
public
function
equals
(
Money
$other
)
{
return
...
...
@@ -73,6 +82,10 @@ class Money
&&
$this
->
amount
==
$other
->
amount
;
}
/**
* @param \Money\Money $other
* @return int
*/
public
function
compare
(
Money
$other
)
{
$this
->
assertSameCurrency
(
$other
);
...
...
@@ -85,11 +98,19 @@ class Money
}
}
/**
* @param \Money\Money $other
* @return bool
*/
public
function
greaterThan
(
Money
$other
)
{
return
1
==
$this
->
compare
(
$other
);
}
/**
* @param \Money\Money $other
* @return bool
*/
public
function
lessThan
(
Money
$other
)
{
return
-
1
==
$this
->
compare
(
$other
);
...
...
@@ -113,13 +134,17 @@ class Money
}
/**
* @return Money\Currency
* @return
\
Money\Currency
*/
public
function
getCurrency
()
{
return
$this
->
currency
;
}
/**
* @param \Money\Money $addend
*@return \Money\Money
*/
public
function
add
(
Money
$addend
)
{
$this
->
assertSameCurrency
(
$addend
);
...
...
@@ -127,6 +152,10 @@ class Money
return
new
self
(
$this
->
amount
+
$addend
->
amount
,
$this
->
currency
);
}
/**
* @param \Money\Money $subtrahend
* @return \Money\Money
*/
public
function
subtract
(
Money
$subtrahend
)
{
$this
->
assertSameCurrency
(
$subtrahend
);
...
...
@@ -135,7 +164,7 @@ class Money
}
/**
* @throws Money\InvalidArgumentException
* @throws
\
Money\InvalidArgumentException
*/
private
function
assertOperand
(
$operand
)
{
...
...
@@ -145,7 +174,7 @@ class Money
}
/**
* @throws Money\InvalidArgumentException
* @throws
\
Money\InvalidArgumentException
*/
private
function
assertRoundingMode
(
$rounding_mode
)
{
...
...
@@ -154,6 +183,11 @@ class Money
}
}
/**
* @param $multiplier
* @param int $rounding_mode
* @return \Money\Money
*/
public
function
multiply
(
$multiplier
,
$rounding_mode
=
self
::
ROUND_HALF_UP
)
{
$this
->
assertOperand
(
$multiplier
);
...
...
@@ -164,6 +198,11 @@ class Money
return
new
Money
(
$product
,
$this
->
currency
);
}
/**
* @param $divisor
* @param int $rounding_mode
* @return \Money\Money
*/
public
function
divide
(
$divisor
,
$rounding_mode
=
self
::
ROUND_HALF_UP
)
{
$this
->
assertOperand
(
$divisor
);
...
...
@@ -177,6 +216,7 @@ class Money
/**
* Allocate the money according to a list of ratio's
* @param array $ratios List of ratio's
* @return \Money\Money
*/
public
function
allocate
(
array
$ratios
)
{
...
...
@@ -215,7 +255,11 @@ class Money
return
$this
->
amount
<
0
;
}
/** @return int */
/**
* @param $string
* @throws \Money\InvalidArgumentException
* @return int
*/
public
static
function
stringToUnits
(
$string
)
{
//@todo extend the regular expression with grouping characters and eventually currencies
...
...
lib/Money/UnknownCurrencyException.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
tests/Money/Tests/CurrencyPairTest.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
tests/Money/Tests/CurrencyTest.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
tests/Money/Tests/MoneyTest.php
View file @
cb1150bf
...
...
@@ -2,7 +2,7 @@
/**
* This file is part of the Money library
*
* Copyright (c) 2011 Mathias Verraes
* Copyright (c) 2011
-2013
Mathias Verraes
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment