@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace WMDE\Euro\Tests\Unit; |
6 | 6 | |
@@ -18,201 +18,201 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @dataProvider unsignedIntegerProvider |
20 | 20 | */ |
21 | - public function testGetCentsReturnsConstructorArgument( int $unsignedInteger ) { |
|
22 | - $amount = Euro::newFromCents( $unsignedInteger ); |
|
23 | - $this->assertSame( $unsignedInteger, $amount->getEuroCents() ); |
|
21 | + public function testGetCentsReturnsConstructorArgument(int $unsignedInteger) { |
|
22 | + $amount = Euro::newFromCents($unsignedInteger); |
|
23 | + $this->assertSame($unsignedInteger, $amount->getEuroCents()); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function unsignedIntegerProvider() { |
27 | 27 | return [ |
28 | - [ 0 ], [ 1 ], [ 2 ], [ 9 ], [ 10 ], [ 11 ], |
|
29 | - [ 99 ], [ 100 ], [ 101 ], [ 999 ], [ 1000 ], [ 1001 ], |
|
28 | + [0], [1], [2], [9], [10], [11], |
|
29 | + [99], [100], [101], [999], [1000], [1001], |
|
30 | 30 | ]; |
31 | 31 | } |
32 | 32 | |
33 | 33 | public function testGivenZero_getEuroFloatReturnsZeroFloat() { |
34 | - $amount = Euro::newFromCents( 0 ); |
|
35 | - $this->assertExactFloat( 0.0, $amount->getEuroFloat() ); |
|
36 | - $this->assertNotSame( 0, $amount->getEuroFloat() ); |
|
34 | + $amount = Euro::newFromCents(0); |
|
35 | + $this->assertExactFloat(0.0, $amount->getEuroFloat()); |
|
36 | + $this->assertNotSame(0, $amount->getEuroFloat()); |
|
37 | 37 | } |
38 | 38 | |
39 | - private function assertExactFloat( float $expected, $actual ) { |
|
40 | - $this->assertInternalType( 'float', $actual ); |
|
41 | - $this->assertEquals( $expected, $actual, '', 0 ); |
|
39 | + private function assertExactFloat(float $expected, $actual) { |
|
40 | + $this->assertInternalType('float', $actual); |
|
41 | + $this->assertEquals($expected, $actual, '', 0); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function testGivenOneEuro_getEuroFloatReturnsOne() { |
45 | - $amount = Euro::newFromCents( 100 ); |
|
46 | - $this->assertExactFloat( 1.0, $amount->getEuroFloat() ); |
|
45 | + $amount = Euro::newFromCents(100); |
|
46 | + $this->assertExactFloat(1.0, $amount->getEuroFloat()); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | public function testGivenOneCent_getEuroFloatReturnsPointZeroOne() { |
50 | - $amount = Euro::newFromCents( 1 ); |
|
51 | - $this->assertExactFloat( 0.01, $amount->getEuroFloat() ); |
|
50 | + $amount = Euro::newFromCents(1); |
|
51 | + $this->assertExactFloat(0.01, $amount->getEuroFloat()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function testGiven33cents_getEuroFloatReturnsPointThreeThree() { |
55 | - $amount = Euro::newFromCents( 33 ); |
|
56 | - $this->assertExactFloat( 0.33, $amount->getEuroFloat() ); |
|
55 | + $amount = Euro::newFromCents(33); |
|
56 | + $this->assertExactFloat(0.33, $amount->getEuroFloat()); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function testGivenNegativeAmount_constructorThrowsException() { |
60 | - $this->expectException( \InvalidArgumentException::class ); |
|
60 | + $this->expectException(\InvalidArgumentException::class); |
|
61 | 61 | Euro::newFromCents( -1 ); |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function testGivenZero_getEuroStringReturnsZeroString() { |
65 | - $amount = Euro::newFromCents( 0 ); |
|
66 | - $this->assertSame( '0.00', $amount->getEuroString() ); |
|
65 | + $amount = Euro::newFromCents(0); |
|
66 | + $this->assertSame('0.00', $amount->getEuroString()); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function testGivenOneEuro_getEuroStringReturnsOnePointZeroZero() { |
70 | - $amount = Euro::newFromCents( 100 ); |
|
71 | - $this->assertSame( '1.00', $amount->getEuroString() ); |
|
70 | + $amount = Euro::newFromCents(100); |
|
71 | + $this->assertSame('1.00', $amount->getEuroString()); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function testGivenTwoEuros_getEuroStringReturnsTwoPointZeroZero() { |
75 | - $amount = Euro::newFromCents( 200 ); |
|
76 | - $this->assertSame( '2.00', $amount->getEuroString() ); |
|
75 | + $amount = Euro::newFromCents(200); |
|
76 | + $this->assertSame('2.00', $amount->getEuroString()); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | public function testGivenOneCent_getEuroStringReturnsZeroPointZeroOne() { |
80 | - $amount = Euro::newFromCents( 1 ); |
|
81 | - $this->assertSame( '0.01', $amount->getEuroString() ); |
|
80 | + $amount = Euro::newFromCents(1); |
|
81 | + $this->assertSame('0.01', $amount->getEuroString()); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | public function testGivenTenCents_getEuroStringReturnsZeroPointOneZero() { |
85 | - $amount = Euro::newFromCents( 10 ); |
|
86 | - $this->assertSame( '0.10', $amount->getEuroString() ); |
|
85 | + $amount = Euro::newFromCents(10); |
|
86 | + $this->assertSame('0.10', $amount->getEuroString()); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public function testGiven1234Cents_getEuroStringReturns12euro34() { |
90 | - $amount = Euro::newFromCents( 1234 ); |
|
91 | - $this->assertSame( '12.34', $amount->getEuroString() ); |
|
90 | + $amount = Euro::newFromCents(1234); |
|
91 | + $this->assertSame('12.34', $amount->getEuroString()); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function testOneEuroString_getsTurnedInto100cents() { |
95 | - $this->assertSame( 100, Euro::newFromString( '1.00' )->getEuroCents() ); |
|
95 | + $this->assertSame(100, Euro::newFromString('1.00')->getEuroCents()); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public function testOneCentString_getsTurnedInto1cents() { |
99 | - $this->assertSame( 1, Euro::newFromString( '0.01' )->getEuroCents() ); |
|
99 | + $this->assertSame(1, Euro::newFromString('0.01')->getEuroCents()); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function testTenCentString_getsTurnedInto10cents() { |
103 | - $this->assertSame( 10, Euro::newFromString( '0.10' )->getEuroCents() ); |
|
103 | + $this->assertSame(10, Euro::newFromString('0.10')->getEuroCents()); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | public function testShortTenCentString_getsTurnedInto10cents() { |
107 | - $this->assertSame( 10, Euro::newFromString( '0.1' )->getEuroCents() ); |
|
107 | + $this->assertSame(10, Euro::newFromString('0.1')->getEuroCents()); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public function testShortOneEuroString_getsTurnedInto100cents() { |
111 | - $this->assertSame( 100, Euro::newFromString( '1' )->getEuroCents() ); |
|
111 | + $this->assertSame(100, Euro::newFromString('1')->getEuroCents()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | public function testOneDecimalOneEuroString_getsTurnedInto100cents() { |
115 | - $this->assertSame( 100, Euro::newFromString( '1.0' )->getEuroCents() ); |
|
115 | + $this->assertSame(100, Euro::newFromString('1.0')->getEuroCents()); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function testMultiDecimalOneEuroString_getsTurnedInto100cents() { |
119 | - $this->assertSame( 100, Euro::newFromString( '1.00000' )->getEuroCents() ); |
|
119 | + $this->assertSame(100, Euro::newFromString('1.00000')->getEuroCents()); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | public function testHandlingOfLargeEuroString() { |
123 | - $this->assertSame( 3133742, Euro::newFromString( '31337.42' )->getEuroCents() ); |
|
123 | + $this->assertSame(3133742, Euro::newFromString('31337.42')->getEuroCents()); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | public function testEuroStringThatCausedRoundingError_doesNotCauseRoundingError() { |
127 | 127 | // Regression test for https://phabricator.wikimedia.org/T183481 |
128 | - $this->assertSame( 870, Euro::newFromString( '8.70' )->getEuroCents() ); |
|
129 | - $this->assertSame( 920, Euro::newFromString( '9.20' )->getEuroCents() ); |
|
128 | + $this->assertSame(870, Euro::newFromString('8.70')->getEuroCents()); |
|
129 | + $this->assertSame(920, Euro::newFromString('9.20')->getEuroCents()); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | public function testEuroStringWithRoundingError_getsRoundedAppropriately() { |
133 | - $this->assertSame( 101, Euro::newFromString( '1.0100000001' )->getEuroCents() ); |
|
134 | - $this->assertSame( 101, Euro::newFromString( '1.010000009999' )->getEuroCents() ); |
|
135 | - $this->assertSame( 101, Euro::newFromString( '1.011' )->getEuroCents() ); |
|
136 | - $this->assertSame( 101, Euro::newFromString( '1.014' )->getEuroCents() ); |
|
137 | - $this->assertSame( 101, Euro::newFromString( '1.0149' )->getEuroCents() ); |
|
138 | - $this->assertSame( 102, Euro::newFromString( '1.015' )->getEuroCents() ); |
|
139 | - $this->assertSame( 102, Euro::newFromString( '1.019' )->getEuroCents() ); |
|
140 | - $this->assertSame( 102, Euro::newFromString( '1.0199999' )->getEuroCents() ); |
|
141 | - $this->assertSame( 870, Euro::newFromString( '8.701' )->getEuroCents() ); |
|
142 | - $this->assertSame( 870, Euro::newFromString( '8.70499' )->getEuroCents() ); |
|
143 | - $this->assertSame( 871, Euro::newFromString( '8.705' )->getEuroCents() ); |
|
144 | - $this->assertSame( 871, Euro::newFromString( '8.705000' )->getEuroCents() ); |
|
145 | - $this->assertSame( 871, Euro::newFromString( '8.705001' )->getEuroCents() ); |
|
146 | - $this->assertSame( 871, Euro::newFromString( '8.709999' )->getEuroCents() ); |
|
133 | + $this->assertSame(101, Euro::newFromString('1.0100000001')->getEuroCents()); |
|
134 | + $this->assertSame(101, Euro::newFromString('1.010000009999')->getEuroCents()); |
|
135 | + $this->assertSame(101, Euro::newFromString('1.011')->getEuroCents()); |
|
136 | + $this->assertSame(101, Euro::newFromString('1.014')->getEuroCents()); |
|
137 | + $this->assertSame(101, Euro::newFromString('1.0149')->getEuroCents()); |
|
138 | + $this->assertSame(102, Euro::newFromString('1.015')->getEuroCents()); |
|
139 | + $this->assertSame(102, Euro::newFromString('1.019')->getEuroCents()); |
|
140 | + $this->assertSame(102, Euro::newFromString('1.0199999')->getEuroCents()); |
|
141 | + $this->assertSame(870, Euro::newFromString('8.701')->getEuroCents()); |
|
142 | + $this->assertSame(870, Euro::newFromString('8.70499')->getEuroCents()); |
|
143 | + $this->assertSame(871, Euro::newFromString('8.705')->getEuroCents()); |
|
144 | + $this->assertSame(871, Euro::newFromString('8.705000')->getEuroCents()); |
|
145 | + $this->assertSame(871, Euro::newFromString('8.705001')->getEuroCents()); |
|
146 | + $this->assertSame(871, Euro::newFromString('8.709999')->getEuroCents()); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | public function testGivenNegativeAmountString_exceptionIsThrown() { |
150 | - $this->expectException( \InvalidArgumentException::class ); |
|
151 | - Euro::newFromString( '-1.00' ); |
|
150 | + $this->expectException(\InvalidArgumentException::class); |
|
151 | + Euro::newFromString('-1.00'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function testGivenStringWithComma_exceptionIsThrown() { |
155 | - $this->expectException( \InvalidArgumentException::class ); |
|
156 | - Euro::newFromString( '1,00' ); |
|
155 | + $this->expectException(\InvalidArgumentException::class); |
|
156 | + Euro::newFromString('1,00'); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | public function testGivenStringWithMultipleDots_ExceptionIsThrown() { |
160 | - $this->expectException( \InvalidArgumentException::class ); |
|
161 | - Euro::newFromString( '1.0.0' ); |
|
160 | + $this->expectException(\InvalidArgumentException::class); |
|
161 | + Euro::newFromString('1.0.0'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function testGivenNonNumber_exceptionIsThrown() { |
165 | - $this->expectException( \InvalidArgumentException::class ); |
|
166 | - Euro::newFromString( '1.00abc' ); |
|
165 | + $this->expectException(\InvalidArgumentException::class); |
|
166 | + Euro::newFromString('1.00abc'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | public function testGivenNegativeFloatAmount_exceptionIsThrown() { |
170 | - $this->expectException( \InvalidArgumentException::class ); |
|
170 | + $this->expectException(\InvalidArgumentException::class); |
|
171 | 171 | Euro::newFromFloat( -1.00 ); |
172 | 172 | } |
173 | 173 | |
174 | 174 | public function testOneEuroFloat_getsTurnedInto100cents() { |
175 | - $this->assertSame( 100, Euro::newFromFloat( 1.0 )->getEuroCents() ); |
|
175 | + $this->assertSame(100, Euro::newFromFloat(1.0)->getEuroCents()); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | public function testOneCentFloat_getsTurnedInto1cent() { |
179 | - $this->assertSame( 1, Euro::newFromFloat( 0.01 )->getEuroCents() ); |
|
179 | + $this->assertSame(1, Euro::newFromFloat(0.01)->getEuroCents()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | public function testTenCentFloat_getsTurnedInto10cents() { |
183 | - $this->assertSame( 10, Euro::newFromFloat( 0.1 )->getEuroCents() ); |
|
183 | + $this->assertSame(10, Euro::newFromFloat(0.1)->getEuroCents()); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | public function testHandlingOfLargeEuroFloat() { |
187 | - $this->assertSame( 3133742, Euro::newFromFloat( 31337.42 )->getEuroCents() ); |
|
187 | + $this->assertSame(3133742, Euro::newFromFloat(31337.42)->getEuroCents()); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | public function testFloatWithRoundingError_getsRoundedAppropriately() { |
191 | - $this->assertSame( 101, Euro::newFromFloat( 1.0100000001 )->getEuroCents() ); |
|
192 | - $this->assertSame( 101, Euro::newFromFloat( 1.010000009999 )->getEuroCents() ); |
|
193 | - $this->assertSame( 101, Euro::newFromFloat( 1.011 )->getEuroCents() ); |
|
194 | - $this->assertSame( 101, Euro::newFromFloat( 1.014 )->getEuroCents() ); |
|
195 | - $this->assertSame( 101, Euro::newFromFloat( 1.0149 )->getEuroCents() ); |
|
196 | - $this->assertSame( 102, Euro::newFromFloat( 1.015 )->getEuroCents() ); |
|
197 | - $this->assertSame( 102, Euro::newFromFloat( 1.019 )->getEuroCents() ); |
|
198 | - $this->assertSame( 102, Euro::newFromFloat( 1.0199999 )->getEuroCents() ); |
|
199 | - $this->assertSame( 870, Euro::newFromFloat( 8.70 )->getEuroCents() ); |
|
191 | + $this->assertSame(101, Euro::newFromFloat(1.0100000001)->getEuroCents()); |
|
192 | + $this->assertSame(101, Euro::newFromFloat(1.010000009999)->getEuroCents()); |
|
193 | + $this->assertSame(101, Euro::newFromFloat(1.011)->getEuroCents()); |
|
194 | + $this->assertSame(101, Euro::newFromFloat(1.014)->getEuroCents()); |
|
195 | + $this->assertSame(101, Euro::newFromFloat(1.0149)->getEuroCents()); |
|
196 | + $this->assertSame(102, Euro::newFromFloat(1.015)->getEuroCents()); |
|
197 | + $this->assertSame(102, Euro::newFromFloat(1.019)->getEuroCents()); |
|
198 | + $this->assertSame(102, Euro::newFromFloat(1.0199999)->getEuroCents()); |
|
199 | + $this->assertSame(870, Euro::newFromFloat(8.70)->getEuroCents()); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | public function testZeroEuroIntegers_isZeroCents() { |
203 | - $this->assertSame( 0, Euro::newFromInt( 0 )->getEuroCents() ); |
|
203 | + $this->assertSame(0, Euro::newFromInt(0)->getEuroCents()); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | public function testOneEuroIntegers_is100cents() { |
207 | - $this->assertSame( 100, Euro::newFromInt( 1 )->getEuroCents() ); |
|
207 | + $this->assertSame(100, Euro::newFromInt(1)->getEuroCents()); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | public function test1337EuroIntegers_is133700cents() { |
211 | - $this->assertSame( 133700, Euro::newFromInt( 1337 )->getEuroCents() ); |
|
211 | + $this->assertSame(133700, Euro::newFromInt(1337)->getEuroCents()); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | public function testGivenNegativeIntegerAmount_exceptionIsThrown() { |
215 | - $this->expectException( \InvalidArgumentException::class ); |
|
215 | + $this->expectException(\InvalidArgumentException::class); |
|
216 | 216 | Euro::newFromInt( -1 ); |
217 | 217 | } |
218 | 218 | |
@@ -220,34 +220,34 @@ discard block |
||
220 | 220 | * @dataProvider euroProvider |
221 | 221 | * @param Euro $euro |
222 | 222 | */ |
223 | - public function testEuroEqualsItself( Euro $euro ) { |
|
224 | - $this->assertTrue( $euro->equals( clone $euro ) ); |
|
223 | + public function testEuroEqualsItself(Euro $euro) { |
|
224 | + $this->assertTrue($euro->equals(clone $euro)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | public function euroProvider() { |
228 | 228 | return [ |
229 | - [ Euro::newFromCents( 0 ) ], |
|
230 | - [ Euro::newFromCents( 1 ) ], |
|
231 | - [ Euro::newFromCents( 99 ) ], |
|
232 | - [ Euro::newFromCents( 100 ) ], |
|
233 | - [ Euro::newFromCents( 9999 ) ], |
|
229 | + [Euro::newFromCents(0)], |
|
230 | + [Euro::newFromCents(1)], |
|
231 | + [Euro::newFromCents(99)], |
|
232 | + [Euro::newFromCents(100)], |
|
233 | + [Euro::newFromCents(9999)], |
|
234 | 234 | ]; |
235 | 235 | } |
236 | 236 | |
237 | 237 | public function testOneCentDoesNotEqualOneEuro() { |
238 | - $this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromInt( 1 ) ) ); |
|
238 | + $this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromInt(1))); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | public function testOneCentDoesNotEqualTwoCents() { |
242 | - $this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromCents( 2 ) ) ); |
|
242 | + $this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromCents(2))); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | public function testOneCentDoesNotEqualOneEuroAndOneCent() { |
246 | - $this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromCents( 101 ) ) ); |
|
246 | + $this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromCents(101))); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | public function test9001centsDoesNotEqual9000cents() { |
250 | - $this->assertFalse( Euro::newFromCents( 9001 )->equals( Euro::newFromCents( 9000 ) ) ); |
|
250 | + $this->assertFalse(Euro::newFromCents(9001)->equals(Euro::newFromCents(9000))); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace WMDE\Euro; |
6 | 6 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * @param int $cents |
22 | 22 | * @throws InvalidArgumentException |
23 | 23 | */ |
24 | - private function __construct( int $cents ) { |
|
25 | - if ( $cents < 0 ) { |
|
26 | - throw new InvalidArgumentException( 'Amount needs to be positive' ); |
|
24 | + private function __construct(int $cents) { |
|
25 | + if ($cents < 0) { |
|
26 | + throw new InvalidArgumentException('Amount needs to be positive'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | $this->cents = $cents; |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @return self |
35 | 35 | * @throws InvalidArgumentException |
36 | 36 | */ |
37 | - public static function newFromCents( int $cents ): self { |
|
38 | - return new self( $cents ); |
|
37 | + public static function newFromCents(int $cents): self { |
|
38 | + return new self($cents); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -49,32 +49,32 @@ discard block |
||
49 | 49 | * @return self |
50 | 50 | * @throws InvalidArgumentException |
51 | 51 | */ |
52 | - public static function newFromString( string $euroAmount ): self { |
|
53 | - if ( !is_numeric( $euroAmount ) ) { |
|
54 | - throw new InvalidArgumentException( 'Not a number' ); |
|
52 | + public static function newFromString(string $euroAmount): self { |
|
53 | + if (!is_numeric($euroAmount)) { |
|
54 | + throw new InvalidArgumentException('Not a number'); |
|
55 | 55 | } |
56 | 56 | |
57 | - $parts = explode( '.', $euroAmount, 2 ); |
|
57 | + $parts = explode('.', $euroAmount, 2); |
|
58 | 58 | |
59 | - $euros = (int)$parts[0]; |
|
60 | - $cents = self::centsFromString( $parts[1] ?? '0' ); |
|
59 | + $euros = (int) $parts[0]; |
|
60 | + $cents = self::centsFromString($parts[1] ?? '0'); |
|
61 | 61 | |
62 | - return new self( $euros * self::$CENTS_PER_EURO + $cents ); |
|
62 | + return new self($euros * self::$CENTS_PER_EURO + $cents); |
|
63 | 63 | } |
64 | 64 | |
65 | - private static function centsFromString( string $cents ): int { |
|
66 | - if ( strlen( $cents ) > self::$DECIMAL_COUNT ) { |
|
67 | - return self::roundCentsToInt( $cents ); |
|
65 | + private static function centsFromString(string $cents): int { |
|
66 | + if (strlen($cents) > self::$DECIMAL_COUNT) { |
|
67 | + return self::roundCentsToInt($cents); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Turn .1 into .10, so it ends up as 10 cents |
71 | - return (int)str_pad( $cents, self::$DECIMAL_COUNT, '0' ); |
|
71 | + return (int) str_pad($cents, self::$DECIMAL_COUNT, '0'); |
|
72 | 72 | } |
73 | 73 | |
74 | - private static function roundCentsToInt( string $cents ): int { |
|
75 | - $centsInt = (int)substr( $cents, 0, self::$DECIMAL_COUNT ); |
|
74 | + private static function roundCentsToInt(string $cents): int { |
|
75 | + $centsInt = (int) substr($cents, 0, self::$DECIMAL_COUNT); |
|
76 | 76 | |
77 | - if ( (int)$cents[self::$DECIMAL_COUNT] >= 5 ) { |
|
77 | + if ((int) $cents[self::$DECIMAL_COUNT] >= 5) { |
|
78 | 78 | $centsInt++; |
79 | 79 | } |
80 | 80 | |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @return self |
91 | 91 | * @throws InvalidArgumentException |
92 | 92 | */ |
93 | - public static function newFromFloat( float $euroAmount ) { |
|
94 | - return new self( intval( |
|
93 | + public static function newFromFloat(float $euroAmount) { |
|
94 | + return new self(intval( |
|
95 | 95 | round( |
96 | - round( $euroAmount, self::$DECIMAL_COUNT ) * self::$CENTS_PER_EURO, |
|
96 | + round($euroAmount, self::$DECIMAL_COUNT) * self::$CENTS_PER_EURO, |
|
97 | 97 | 0 |
98 | 98 | ) |
99 | - ) ); |
|
99 | + )); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @return self |
105 | 105 | * @throws InvalidArgumentException |
106 | 106 | */ |
107 | - public static function newFromInt( int $euroAmount ) { |
|
108 | - return new self( $euroAmount * self::$CENTS_PER_EURO ); |
|
107 | + public static function newFromInt(int $euroAmount) { |
|
108 | + return new self($euroAmount * self::$CENTS_PER_EURO); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | public function getEuroCents(): int { |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | * Returns the euro amount as string with two decimals always present in format "42.00". |
121 | 121 | */ |
122 | 122 | public function getEuroString(): string { |
123 | - return number_format( $this->getEuroFloat(), self::$DECIMAL_COUNT, '.', '' ); |
|
123 | + return number_format($this->getEuroFloat(), self::$DECIMAL_COUNT, '.', ''); |
|
124 | 124 | } |
125 | 125 | |
126 | - public function equals( Euro $euro ): bool { |
|
126 | + public function equals(Euro $euro): bool { |
|
127 | 127 | return $this->cents === $euro->cents; |
128 | 128 | } |
129 | 129 |