Open Journal Systems  3.3.0
Money\Money Class Reference
Inheritance diagram for Money\Money:

Public Member Functions

 __construct ($amount, Currency $currency)
 
 absolute ()
 
 add (Money ... $addends)
 
 allocate (array $ratios)
 
 allocateTo ($n)
 
 compare (Money $other)
 
 divide ($divisor, $roundingMode=self::ROUND_HALF_UP)
 
 equals (Money $other)
 
 getAmount ()
 
 getCurrency ()
 
 greaterThan (Money $other)
 
 greaterThanOrEqual (Money $other)
 
 isNegative ()
 
 isPositive ()
 
 isSameCurrency (Money $other)
 
 isZero ()
 
 jsonSerialize ()
 
 lessThan (Money $other)
 
 lessThanOrEqual (Money $other)
 
 mod (Money $divisor)
 
 multiply ($multiplier, $roundingMode=self::ROUND_HALF_UP)
 
 negative ()
 
 ratioOf (Money $money)
 
 subtract (Money ... $subtrahends)
 

Static Public Member Functions

static avg (self $first, self ... $collection)
 
static max (self $first, self ... $collection)
 
static min (self $first, self ... $collection)
 
static registerCalculator ($calculator)
 
static sum (self $first, self ... $collection)
 

Data Fields

const ROUND_DOWN = 6
 
const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN
 
const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN
 
const ROUND_HALF_NEGATIVE_INFINITY = 8
 
const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD
 
const ROUND_HALF_POSITIVE_INFINITY = 7
 
const ROUND_HALF_UP = PHP_ROUND_HALF_UP
 
const ROUND_UP = 5
 

Detailed Description

Money Value Object.

Author
Mathias Verraes

@psalm-immutable

Definition at line 16 of file Money.php.

Constructor & Destructor Documentation

◆ __construct()

Money\Money::__construct (   $amount,
Currency  $currency 
)
Parameters
int | string$amountAmount, expressed in the smallest units of $currency (eg cents)
Currency$currency
Exceptions

Definition at line 74 of file Money.php.

References Money\Number\fromString().

Member Function Documentation

◆ absolute()

Money\Money::absolute ( )
Returns
Money

Definition at line 479 of file Money.php.

◆ add()

Money\Money::add ( Money ...  $addends)

Returns a new Money object that represents the sum of this and an other Money object.

Parameters
Money[]$addends
Returns
Money

Definition at line 229 of file Money.php.

◆ allocate()

Money\Money::allocate ( array  $ratios)

Allocate the money according to a list of ratios.

Parameters
array$ratios
Returns
Money[]

Definition at line 376 of file Money.php.

◆ allocateTo()

Money\Money::allocateTo (   $n)

Allocate the money among N targets.

Parameters
int$n
Returns
Money[]
Exceptions

Definition at line 428 of file Money.php.

◆ avg()

static Money\Money::avg ( self  $first,
self ...  $collection 
)
static
Parameters
Money$first
Money...$collection
Returns
Money

@psalm-pure

Definition at line 598 of file Money.php.

◆ compare()

Money\Money::compare ( Money  $other)

Returns an integer less than, equal to, or greater than zero if the value of this object is considered to be respectively less than, equal to, or greater than the other.

Parameters
Money$other
Returns
int

Definition at line 150 of file Money.php.

◆ divide()

Money\Money::divide (   $divisor,
  $roundingMode = self::ROUND_HALF_UP 
)

Returns a new Money object that represents the divided value by the given factor.

Parameters
float | int | string$divisor
int$roundingMode
Returns
Money

Definition at line 337 of file Money.php.

References Money\Number\fromNumber().

◆ equals()

Money\Money::equals ( Money  $other)

Checks whether the value represented by this object equals to the other.

Parameters
Money$other
Returns
bool

Definition at line 136 of file Money.php.

◆ getAmount()

Money\Money::getAmount ( )

◆ getCurrency()

◆ greaterThan()

Money\Money::greaterThan ( Money  $other)

Checks whether the value represented by this object is greater than the other.

Parameters
Money$other
Returns
bool

Definition at line 164 of file Money.php.

◆ greaterThanOrEqual()

Money\Money::greaterThanOrEqual ( Money  $other)
Parameters
\Money\Money$other
Returns
bool

Definition at line 174 of file Money.php.

◆ isNegative()

Money\Money::isNegative ( )

Checks if the value represented by this object is negative.

Returns
bool

Definition at line 517 of file Money.php.

◆ isPositive()

Money\Money::isPositive ( )

Checks if the value represented by this object is positive.

Returns
bool

Definition at line 507 of file Money.php.

◆ isSameCurrency()

Money\Money::isSameCurrency ( Money  $other)

Checks whether a Money has the same Currency as this.

Parameters
Money$other
Returns
bool

Definition at line 110 of file Money.php.

◆ isZero()

Money\Money::isZero ( )

Checks if the value represented by this object is zero.

Returns
bool

Definition at line 497 of file Money.php.

Referenced by Money\Money\ratioOf().

◆ jsonSerialize()

Money\Money::jsonSerialize ( )

{}

Returns
array

Definition at line 527 of file Money.php.

◆ lessThan()

Money\Money::lessThan ( Money  $other)

Checks whether the value represented by this object is less than the other.

Parameters
Money$other
Returns
bool

Definition at line 186 of file Money.php.

◆ lessThanOrEqual()

Money\Money::lessThanOrEqual ( Money  $other)
Parameters
\Money\Money$other
Returns
bool

Definition at line 196 of file Money.php.

◆ max()

static Money\Money::max ( self  $first,
self ...  $collection 
)
static
Parameters
Money$first
Money...$collection
Returns
Money

@psalm-pure

Definition at line 564 of file Money.php.

◆ min()

static Money\Money::min ( self  $first,
self ...  $collection 
)
static
Parameters
Money$first
Money...$collection
Returns
Money

@psalm-pure

Definition at line 543 of file Money.php.

◆ mod()

Money\Money::mod ( Money  $divisor)

Returns a new Money object that represents the remainder after dividing the value by the given factor.

Parameters
Money$divisor
Returns
Money

Definition at line 362 of file Money.php.

◆ multiply()

Money\Money::multiply (   $multiplier,
  $roundingMode = self::ROUND_HALF_UP 
)

Returns a new Money object that represents the multiplied value by the given factor.

Parameters
float | int | string$multiplier
int$roundingMode
Returns
Money

Definition at line 318 of file Money.php.

Referenced by Money\Converter\convert().

◆ negative()

Money\Money::negative ( )
Returns
Money

Definition at line 487 of file Money.php.

◆ ratioOf()

Money\Money::ratioOf ( Money  $money)
Parameters
Money$money
Returns
string

Definition at line 446 of file Money.php.

References Money\Money\isZero().

◆ registerCalculator()

static Money\Money::registerCalculator (   $calculator)
static
Parameters
string$calculator

Definition at line 606 of file Money.php.

◆ subtract()

Money\Money::subtract ( Money ...  $subtrahends)

Returns a new Money object that represents the difference of this and an other Money object.

Parameters
Money[]$subtrahends
Returns
Money

@psalm-pure

Definition at line 253 of file Money.php.

◆ sum()

static Money\Money::sum ( self  $first,
self ...  $collection 
)
static
Parameters
Money$first
Money...$collection
Returns
Money

@psalm-pure

Definition at line 585 of file Money.php.

Field Documentation

◆ ROUND_DOWN

const Money\Money::ROUND_DOWN = 6

Definition at line 30 of file Money.php.

◆ ROUND_HALF_DOWN

const Money\Money::ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN

◆ ROUND_HALF_EVEN

const Money\Money::ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN

◆ ROUND_HALF_NEGATIVE_INFINITY

const Money\Money::ROUND_HALF_NEGATIVE_INFINITY = 8

◆ ROUND_HALF_ODD

const Money\Money::ROUND_HALF_ODD = PHP_ROUND_HALF_ODD

◆ ROUND_HALF_POSITIVE_INFINITY

const Money\Money::ROUND_HALF_POSITIVE_INFINITY = 7

◆ ROUND_HALF_UP

const Money\Money::ROUND_HALF_UP = PHP_ROUND_HALF_UP

◆ ROUND_UP

const Money\Money::ROUND_UP = 5

Definition at line 28 of file Money.php.


The documentation for this class was generated from the following file: