-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmountInterface.php
91 lines (71 loc) · 2.21 KB
/
AmountInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace SonsOfPHP\Contract\Money;
/**
* Amount.
*
* The amount is used to represent the Numerical Value of the Money.
*
* The amount SHOULD be represented in the smallest form of the currency. So
* for USD a value of `420` would represent `$4.20`.
*
* @author Joshua Estes <joshua@sonsofphp.com>
*/
interface AmountInterface // extends \Stringable
{
/**
* Allows you to run you own operations of the amount.
*/
public function with(AmountOperatorInterface $operator): static;
/**
* Allows you to ask different questions about the amount and get
* different results returned to you.
*/
public function query(AmountQueryInterface $query)/*: mixed*/;
/**
* Returns the value for this amount as a string.
*/
public function toString(): string;
/**
* Returns the value for this amount as a integer.
*/
public function toInt(): int;
/**
* Returns the value for this amount as a float.
*/
//public function toFloat(): float;
/**
* Returns the value that this is for the object.
*/
public function getAmount(): string;
/**
* Add amounts together.
*/
public function add(AmountInterface $amount): static;
/**
* Subtract amounts from each other.
*
* Example:
* $amount1 = 100
* $amount2 = 50
* $amount1->subtract($amount2) == 50
* $amount2->subtract($amount1) == -50
*/
public function subtract(AmountInterface $amount): static;
/**
* Multiply amount by a specific amount.
*/
public function multiply(/*int */$multiplier): static;
/**
* Divide the amount by a specific amount.
*/
public function divide(/*int */$divisor): static;
public function isEqualTo(AmountInterface $amount): bool;
public function isGreaterThan(AmountInterface $amount): bool;
public function isGreaterThanOrEqualTo(AmountInterface $amount): bool;
public function isLessThan(AmountInterface $amount): bool;
public function isLessThanOrEqualTo(AmountInterface $amount): bool;
public function isNegative(): bool;
public function isPositive(): bool;
public function isZero(): bool;
}