Completed
Branch FET-10619-money-entity (77ea92)
by
unknown
102:26 queued 91:05
created

Currency::subunitOrderOfMagnitudeDiff()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\values\currency;
4
5
use EventEspresso\core\entities\Label;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit;
8
9
10
11
/**
12
 * Class Currency
13
 * DTO for data pertaining to a currency
14
 *
15
 * @package       Event Espresso
16
 * @author        Brent Christensen
17
 * @since         $VID:$
18
 */
19
class Currency
20
{
21
22
    /**
23
     * eg 'US'
24
     *
25
     * @var string $code
26
     */
27
    private $code;
28
29
    /**
30
     * @var Label $label
31
     */
32
    private $label;
33
34
    /**
35
     * currency sign
36
     *
37
     * @var string $sign
38
     * eg '$'
39
     */
40
    private $sign;
41
42
    /**
43
     * Whether the currency sign should come before the number or not
44
     *
45
     * @var boolean $sign_b4
46
     */
47
    private $sign_b4;
48
49
    /**
50
     * How many digits should come after the decimal place
51
     *
52
     * @var int $decimal_places
53
     */
54
    private $decimal_places;
55
56
    /**
57
     * Symbol to use for decimal mark
58
     *
59
     * @var string $decimal_mark
60
     * eg '.'
61
     */
62
    private $decimal_mark;
63
64
    /**
65
     * Symbol to use for thousands
66
     *
67
     * @var string $thousands
68
     * eg ','
69
     */
70
    private $thousands;
71
72
    /**
73
     * Used to convert between the currency's units and subunits.
74
     * subunits = units * 10 to-the-power-of $subunits_ratio
75
     * @var int
76
     */
77
    private $subunit_order_of_mag_diff;
78
79
80
81
    /**
82
     * Currency constructor.
83
     *
84
     * @param string $code
85
     * @param Label  $label
86
     * @param string $sign
87
     * @param bool   $sign_b4
88
     * @param int    $decimal_places            the number of decimal places to use when
89
     *                               DISPLAYING the currency
90
     * @param string $decimal_mark
91
     * @param string $thousands
92
     * @param int    $subunit_order_of_mag_diff the difference between units and subunits
93
     *                               is 10 to-the-power-of-this
94
     */
95
    public function __construct(
96
        $code,
97
        Label $label,
98
        $sign,
99
        $sign_b4,
100
        $decimal_places,
101
        $decimal_mark,
102
        $thousands,
103
        $subunit_order_of_mag_diff
104
    ) {
105
        $this->code           = $code;
106
        $this->label          = $label;
107
        $this->sign           = $sign;
108
        $this->sign_b4        = $sign_b4;
109
        $this->decimal_places = $decimal_places;
110
        $this->decimal_mark   = $decimal_mark;
111
        $this->thousands      = $thousands;
112
        $this->subunit_order_of_mag_diff = $subunit_order_of_mag_diff;
113
    }
114
115
116
117
    /**
118
     * returns true if this currency is the same as the supplied currency
119
     *
120
     * @param Currency $other
121
     * @return bool
122
     */
123
    public function equals(Currency $other)
124
    {
125
        return $this->code() === $other->code();
126
    }
127
128
129
130
    /**
131
     * @return string
132
     */
133
    public function code()
134
    {
135
        return $this->code;
136
    }
137
138
139
140
    /**
141
     * @return string
142
     */
143
    public function name()
144
    {
145
        return $this->label->singular();
146
    }
147
148
149
150
    /**
151
     * @return string
152
     */
153
    public function plural()
154
    {
155
        return $this->label->plural();
156
    }
157
158
159
160
    /**
161
     * @return string
162
     */
163
    public function sign()
164
    {
165
        return $this->sign;
166
    }
167
168
169
170
    /**
171
     * @return bool
172
     */
173
    public function signB4()
174
    {
175
        return $this->sign_b4;
176
    }
177
178
179
180
    /**
181
     * @return int
182
     */
183
    public function decimalPlaces()
184
    {
185
        return $this->decimal_places;
186
    }
187
188
189
190
    /**
191
     * @return string
192
     */
193
    public function decimalMark()
194
    {
195
        return $this->decimal_mark;
196
    }
197
198
199
200
    /**
201
     * @return string
202
     */
203
    public function thousands()
204
    {
205
        return $this->thousands;
206
    }
207
208
209
210
    /**
211
     * The difference between currency units and subunits
212
     * is 10-to-the-power-of-this.
213
     * DecimalMark is used for display, this is used for calculations
214
     * @return int
215
     */
216
    public function subunitOrderOfMagnitudeDiff()
217
    {
218
        return $this->subunit_order_of_mag_diff;
219
    }
220
221
222
223
    /**
224
     * @return string
225
     */
226
    public function __toString()
227
    {
228
        return $this->code();
229
    }
230
231
232
233
}
234
// End of file Currency.php
235
// Location: core/entities/money/Currency.php
236