Completed
Pull Request — master (#9)
by Gabriel
02:39
created
tests/bootstrap.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5
-if ( PHP_SAPI !== 'cli' ) {
6
-	die( 'Not an entry point' );
5
+if (PHP_SAPI !== 'cli') {
6
+	die('Not an entry point');
7 7
 }
8 8
 
9 9
 error_reporting( -1 );
10
-ini_set( 'display_errors', '1' );
10
+ini_set('display_errors', '1');
11 11
 
12
-if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) {
13
-	die( 'You need to install this package with Composer before you can run the tests' );
12
+if (!is_readable(__DIR__.'/../vendor/autoload.php')) {
13
+	die('You need to install this package with Composer before you can run the tests');
14 14
 }
15 15
 
16
-require __DIR__ . '/../vendor/autoload.php';
16
+require __DIR__.'/../vendor/autoload.php';
Please login to merge, or discard this patch.
tests/Unit/EuroErisTest.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -19,43 +19,43 @@  discard block
 block discarded – undo
19 19
 	use TestTrait;
20 20
 
21 21
 	public function testGivenNegativeAmount_constructorThrowsException() {
22
-		$this->forAll( Generator\neg() )
23
-			->then( function( int $negativeInteger ) {
24
-				$this->expectException( \InvalidArgumentException::class );
25
-				Euro::newFromCents( $negativeInteger );
22
+		$this->forAll(Generator\neg())
23
+			->then(function(int $negativeInteger) {
24
+				$this->expectException(\InvalidArgumentException::class);
25
+				Euro::newFromCents($negativeInteger);
26 26
 			} );
27 27
 	}
28 28
 
29 29
 	public function testGetCentsReturnsConstructorArgument() {
30
-		$this->limitTo( 10000 )
31
-			->forAll( Generator\choose( 0, 100 * 100 ) )
32
-			->then( function( int $unsignedInteger ) {
33
-				$amount = Euro::newFromCents( $unsignedInteger );
34
-				$this->assertSame( $unsignedInteger, $amount->getEuroCents() );
30
+		$this->limitTo(10000)
31
+			->forAll(Generator\choose(0, 100 * 100))
32
+			->then(function(int $unsignedInteger) {
33
+				$amount = Euro::newFromCents($unsignedInteger);
34
+				$this->assertSame($unsignedInteger, $amount->getEuroCents());
35 35
 			} );
36 36
 	}
37 37
 
38 38
 	public function testEquality() {
39
-		$this->limitTo( 10000 )
40
-			->forAll( Generator\choose( 0, 100 * 100 ) )
41
-			->then( function( int $unsignedInteger ) {
42
-				$amount = Euro::newFromCents( $unsignedInteger );
43
-				$this->assertTrue( $amount->equals( Euro::newFromCents( $unsignedInteger ) ) );
39
+		$this->limitTo(10000)
40
+			->forAll(Generator\choose(0, 100 * 100))
41
+			->then(function(int $unsignedInteger) {
42
+				$amount = Euro::newFromCents($unsignedInteger);
43
+				$this->assertTrue($amount->equals(Euro::newFromCents($unsignedInteger)));
44 44
 			} );
45 45
 	}
46 46
 
47 47
 	public function testNewFromString() {
48
-		$this->limitTo( 10000 )
49
-			->forAll( Generator\choose( 0, 100 ), Generator\choose( 0, 99 ) )
50
-			->then( function( int $firstInt, int $secondInt ) {
48
+		$this->limitTo(10000)
49
+			->forAll(Generator\choose(0, 100), Generator\choose(0, 99))
50
+			->then(function(int $firstInt, int $secondInt) {
51 51
 				$euroString =
52
-					(string)$firstInt
52
+					(string) $firstInt
53 53
 					. '.'
54
-					. str_pad( (string)$secondInt, 2, '0', STR_PAD_LEFT );
54
+					. str_pad((string) $secondInt, 2, '0', STR_PAD_LEFT);
55 55
 
56 56
 				$this->assertSame(
57 57
 					$firstInt * 100 + $secondInt,
58
-					Euro::newFromString( $euroString )->getEuroCents()
58
+					Euro::newFromString($euroString)->getEuroCents()
59 59
 				);
60 60
 			} );
61 61
 	}
Please login to merge, or discard this patch.
tests/Unit/EuroTest.php 1 patch
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -19,201 +19,201 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @dataProvider unsignedIntegerProvider
21 21
 	 */
22
-	public function testGetCentsReturnsConstructorArgument( int $unsignedInteger ) {
23
-		$amount = Euro::newFromCents( $unsignedInteger );
24
-		$this->assertSame( $unsignedInteger, $amount->getEuroCents() );
22
+	public function testGetCentsReturnsConstructorArgument(int $unsignedInteger) {
23
+		$amount = Euro::newFromCents($unsignedInteger);
24
+		$this->assertSame($unsignedInteger, $amount->getEuroCents());
25 25
 	}
26 26
 
27 27
 	public function unsignedIntegerProvider() {
28 28
 		return [
29
-			[ 0 ], [ 1 ], [ 2 ], [ 9 ], [ 10 ], [ 11 ],
30
-			[ 99 ], [ 100 ], [ 101 ], [ 999 ], [ 1000 ], [ 1001 ],
29
+			[0], [1], [2], [9], [10], [11],
30
+			[99], [100], [101], [999], [1000], [1001],
31 31
 		];
32 32
 	}
33 33
 
34 34
 	public function testGivenZero_getEuroFloatReturnsZeroFloat() {
35
-		$amount = Euro::newFromCents( 0 );
36
-		$this->assertExactFloat( 0.0, $amount->getEuroFloat() );
37
-		$this->assertNotSame( 0, $amount->getEuroFloat() );
35
+		$amount = Euro::newFromCents(0);
36
+		$this->assertExactFloat(0.0, $amount->getEuroFloat());
37
+		$this->assertNotSame(0, $amount->getEuroFloat());
38 38
 	}
39 39
 
40
-	private function assertExactFloat( float $expected, $actual ) {
41
-		$this->assertInternalType( 'float', $actual );
42
-		$this->assertEquals( $expected, $actual, '', 0 );
40
+	private function assertExactFloat(float $expected, $actual) {
41
+		$this->assertInternalType('float', $actual);
42
+		$this->assertEquals($expected, $actual, '', 0);
43 43
 	}
44 44
 
45 45
 	public function testGivenOneEuro_getEuroFloatReturnsOne() {
46
-		$amount = Euro::newFromCents( 100 );
47
-		$this->assertExactFloat( 1.0, $amount->getEuroFloat() );
46
+		$amount = Euro::newFromCents(100);
47
+		$this->assertExactFloat(1.0, $amount->getEuroFloat());
48 48
 	}
49 49
 
50 50
 	public function testGivenOneCent_getEuroFloatReturnsPointZeroOne() {
51
-		$amount = Euro::newFromCents( 1 );
52
-		$this->assertExactFloat( 0.01, $amount->getEuroFloat() );
51
+		$amount = Euro::newFromCents(1);
52
+		$this->assertExactFloat(0.01, $amount->getEuroFloat());
53 53
 	}
54 54
 
55 55
 	public function testGiven33cents_getEuroFloatReturnsPointThreeThree() {
56
-		$amount = Euro::newFromCents( 33 );
57
-		$this->assertExactFloat( 0.33, $amount->getEuroFloat() );
56
+		$amount = Euro::newFromCents(33);
57
+		$this->assertExactFloat(0.33, $amount->getEuroFloat());
58 58
 	}
59 59
 
60 60
 	public function testGivenNegativeAmount_constructorThrowsException() {
61
-		$this->expectException( \InvalidArgumentException::class );
61
+		$this->expectException(\InvalidArgumentException::class);
62 62
 		Euro::newFromCents( -1 );
63 63
 	}
64 64
 
65 65
 	public function testGivenZero_getEuroStringReturnsZeroString() {
66
-		$amount = Euro::newFromCents( 0 );
67
-		$this->assertSame( '0.00', $amount->getEuroString() );
66
+		$amount = Euro::newFromCents(0);
67
+		$this->assertSame('0.00', $amount->getEuroString());
68 68
 	}
69 69
 
70 70
 	public function testGivenOneEuro_getEuroStringReturnsOnePointZeroZero() {
71
-		$amount = Euro::newFromCents( 100 );
72
-		$this->assertSame( '1.00', $amount->getEuroString() );
71
+		$amount = Euro::newFromCents(100);
72
+		$this->assertSame('1.00', $amount->getEuroString());
73 73
 	}
74 74
 
75 75
 	public function testGivenTwoEuros_getEuroStringReturnsTwoPointZeroZero() {
76
-		$amount = Euro::newFromCents( 200 );
77
-		$this->assertSame( '2.00', $amount->getEuroString() );
76
+		$amount = Euro::newFromCents(200);
77
+		$this->assertSame('2.00', $amount->getEuroString());
78 78
 	}
79 79
 
80 80
 	public function testGivenOneCent_getEuroStringReturnsZeroPointZeroOne() {
81
-		$amount = Euro::newFromCents( 1 );
82
-		$this->assertSame( '0.01', $amount->getEuroString() );
81
+		$amount = Euro::newFromCents(1);
82
+		$this->assertSame('0.01', $amount->getEuroString());
83 83
 	}
84 84
 
85 85
 	public function testGivenTenCents_getEuroStringReturnsZeroPointOneZero() {
86
-		$amount = Euro::newFromCents( 10 );
87
-		$this->assertSame( '0.10', $amount->getEuroString() );
86
+		$amount = Euro::newFromCents(10);
87
+		$this->assertSame('0.10', $amount->getEuroString());
88 88
 	}
89 89
 
90 90
 	public function testGiven1234Cents_getEuroStringReturns12euro34() {
91
-		$amount = Euro::newFromCents( 1234 );
92
-		$this->assertSame( '12.34', $amount->getEuroString() );
91
+		$amount = Euro::newFromCents(1234);
92
+		$this->assertSame('12.34', $amount->getEuroString());
93 93
 	}
94 94
 
95 95
 	public function testOneEuroString_getsTurnedInto100cents() {
96
-		$this->assertSame( 100, Euro::newFromString( '1.00' )->getEuroCents() );
96
+		$this->assertSame(100, Euro::newFromString('1.00')->getEuroCents());
97 97
 	}
98 98
 
99 99
 	public function testOneCentString_getsTurnedInto1cents() {
100
-		$this->assertSame( 1, Euro::newFromString( '0.01' )->getEuroCents() );
100
+		$this->assertSame(1, Euro::newFromString('0.01')->getEuroCents());
101 101
 	}
102 102
 
103 103
 	public function testTenCentString_getsTurnedInto10cents() {
104
-		$this->assertSame( 10, Euro::newFromString( '0.10' )->getEuroCents() );
104
+		$this->assertSame(10, Euro::newFromString('0.10')->getEuroCents());
105 105
 	}
106 106
 
107 107
 	public function testShortTenCentString_getsTurnedInto10cents() {
108
-		$this->assertSame( 10, Euro::newFromString( '0.1' )->getEuroCents() );
108
+		$this->assertSame(10, Euro::newFromString('0.1')->getEuroCents());
109 109
 	}
110 110
 
111 111
 	public function testShortOneEuroString_getsTurnedInto100cents() {
112
-		$this->assertSame( 100, Euro::newFromString( '1' )->getEuroCents() );
112
+		$this->assertSame(100, Euro::newFromString('1')->getEuroCents());
113 113
 	}
114 114
 
115 115
 	public function testOneDecimalOneEuroString_getsTurnedInto100cents() {
116
-		$this->assertSame( 100, Euro::newFromString( '1.0' )->getEuroCents() );
116
+		$this->assertSame(100, Euro::newFromString('1.0')->getEuroCents());
117 117
 	}
118 118
 
119 119
 	public function testMultiDecimalOneEuroString_getsTurnedInto100cents() {
120
-		$this->assertSame( 100, Euro::newFromString( '1.00000' )->getEuroCents() );
120
+		$this->assertSame(100, Euro::newFromString('1.00000')->getEuroCents());
121 121
 	}
122 122
 
123 123
 	public function testHandlingOfLargeEuroString() {
124
-		$this->assertSame( 3133742, Euro::newFromString( '31337.42' )->getEuroCents() );
124
+		$this->assertSame(3133742, Euro::newFromString('31337.42')->getEuroCents());
125 125
 	}
126 126
 
127 127
 	public function testEuroStringThatCausedRoundingError_doesNotCauseRoundingError() {
128 128
 		// Regression test for https://phabricator.wikimedia.org/T183481
129
-		$this->assertSame( 870, Euro::newFromString( '8.70' )->getEuroCents() );
130
-		$this->assertSame( 920, Euro::newFromString( '9.20' )->getEuroCents() );
129
+		$this->assertSame(870, Euro::newFromString('8.70')->getEuroCents());
130
+		$this->assertSame(920, Euro::newFromString('9.20')->getEuroCents());
131 131
 	}
132 132
 
133 133
 	public function testEuroStringWithRoundingError_getsRoundedAppropriately() {
134
-		$this->assertSame( 101, Euro::newFromString( '1.0100000001' )->getEuroCents() );
135
-		$this->assertSame( 101, Euro::newFromString( '1.010000009999' )->getEuroCents() );
136
-		$this->assertSame( 101, Euro::newFromString( '1.011' )->getEuroCents() );
137
-		$this->assertSame( 101, Euro::newFromString( '1.014' )->getEuroCents() );
138
-		$this->assertSame( 101, Euro::newFromString( '1.0149' )->getEuroCents() );
139
-		$this->assertSame( 102, Euro::newFromString( '1.015' )->getEuroCents() );
140
-		$this->assertSame( 102, Euro::newFromString( '1.019' )->getEuroCents() );
141
-		$this->assertSame( 102, Euro::newFromString( '1.0199999' )->getEuroCents() );
142
-		$this->assertSame( 870, Euro::newFromString( '8.701' )->getEuroCents() );
143
-		$this->assertSame( 870, Euro::newFromString( '8.70499' )->getEuroCents() );
144
-		$this->assertSame( 871, Euro::newFromString( '8.705' )->getEuroCents() );
145
-		$this->assertSame( 871, Euro::newFromString( '8.705000' )->getEuroCents() );
146
-		$this->assertSame( 871, Euro::newFromString( '8.705001' )->getEuroCents() );
147
-		$this->assertSame( 871, Euro::newFromString( '8.709999' )->getEuroCents() );
134
+		$this->assertSame(101, Euro::newFromString('1.0100000001')->getEuroCents());
135
+		$this->assertSame(101, Euro::newFromString('1.010000009999')->getEuroCents());
136
+		$this->assertSame(101, Euro::newFromString('1.011')->getEuroCents());
137
+		$this->assertSame(101, Euro::newFromString('1.014')->getEuroCents());
138
+		$this->assertSame(101, Euro::newFromString('1.0149')->getEuroCents());
139
+		$this->assertSame(102, Euro::newFromString('1.015')->getEuroCents());
140
+		$this->assertSame(102, Euro::newFromString('1.019')->getEuroCents());
141
+		$this->assertSame(102, Euro::newFromString('1.0199999')->getEuroCents());
142
+		$this->assertSame(870, Euro::newFromString('8.701')->getEuroCents());
143
+		$this->assertSame(870, Euro::newFromString('8.70499')->getEuroCents());
144
+		$this->assertSame(871, Euro::newFromString('8.705')->getEuroCents());
145
+		$this->assertSame(871, Euro::newFromString('8.705000')->getEuroCents());
146
+		$this->assertSame(871, Euro::newFromString('8.705001')->getEuroCents());
147
+		$this->assertSame(871, Euro::newFromString('8.709999')->getEuroCents());
148 148
 	}
149 149
 
150 150
 	public function testGivenNegativeAmountString_exceptionIsThrown() {
151
-		$this->expectException( \InvalidArgumentException::class );
152
-		Euro::newFromString( '-1.00' );
151
+		$this->expectException(\InvalidArgumentException::class);
152
+		Euro::newFromString('-1.00');
153 153
 	}
154 154
 
155 155
 	public function testGivenStringWithComma_exceptionIsThrown() {
156
-		$this->expectException( \InvalidArgumentException::class );
157
-		Euro::newFromString( '1,00' );
156
+		$this->expectException(\InvalidArgumentException::class);
157
+		Euro::newFromString('1,00');
158 158
 	}
159 159
 
160 160
 	public function testGivenStringWithMultipleDots_ExceptionIsThrown() {
161
-		$this->expectException( \InvalidArgumentException::class );
162
-		Euro::newFromString( '1.0.0' );
161
+		$this->expectException(\InvalidArgumentException::class);
162
+		Euro::newFromString('1.0.0');
163 163
 	}
164 164
 
165 165
 	public function testGivenNonNumber_exceptionIsThrown() {
166
-		$this->expectException( \InvalidArgumentException::class );
167
-		Euro::newFromString( '1.00abc' );
166
+		$this->expectException(\InvalidArgumentException::class);
167
+		Euro::newFromString('1.00abc');
168 168
 	}
169 169
 
170 170
 	public function testGivenNegativeFloatAmount_exceptionIsThrown() {
171
-		$this->expectException( \InvalidArgumentException::class );
171
+		$this->expectException(\InvalidArgumentException::class);
172 172
 		Euro::newFromFloat( -1.00 );
173 173
 	}
174 174
 
175 175
 	public function testOneEuroFloat_getsTurnedInto100cents() {
176
-		$this->assertSame( 100, Euro::newFromFloat( 1.0 )->getEuroCents() );
176
+		$this->assertSame(100, Euro::newFromFloat(1.0)->getEuroCents());
177 177
 	}
178 178
 
179 179
 	public function testOneCentFloat_getsTurnedInto1cent() {
180
-		$this->assertSame( 1, Euro::newFromFloat( 0.01 )->getEuroCents() );
180
+		$this->assertSame(1, Euro::newFromFloat(0.01)->getEuroCents());
181 181
 	}
182 182
 
183 183
 	public function testTenCentFloat_getsTurnedInto10cents() {
184
-		$this->assertSame( 10, Euro::newFromFloat( 0.1 )->getEuroCents() );
184
+		$this->assertSame(10, Euro::newFromFloat(0.1)->getEuroCents());
185 185
 	}
186 186
 
187 187
 	public function testHandlingOfLargeEuroFloat() {
188
-		$this->assertSame( 3133742, Euro::newFromFloat( 31337.42 )->getEuroCents() );
188
+		$this->assertSame(3133742, Euro::newFromFloat(31337.42)->getEuroCents());
189 189
 	}
190 190
 
191 191
 	public function testFloatWithRoundingError_getsRoundedAppropriately() {
192
-		$this->assertSame( 101, Euro::newFromFloat( 1.0100000001 )->getEuroCents() );
193
-		$this->assertSame( 101, Euro::newFromFloat( 1.010000009999 )->getEuroCents() );
194
-		$this->assertSame( 101, Euro::newFromFloat( 1.011 )->getEuroCents() );
195
-		$this->assertSame( 101, Euro::newFromFloat( 1.014 )->getEuroCents() );
196
-		$this->assertSame( 101, Euro::newFromFloat( 1.0149 )->getEuroCents() );
197
-		$this->assertSame( 102, Euro::newFromFloat( 1.015 )->getEuroCents() );
198
-		$this->assertSame( 102, Euro::newFromFloat( 1.019 )->getEuroCents() );
199
-		$this->assertSame( 102, Euro::newFromFloat( 1.0199999 )->getEuroCents() );
200
-		$this->assertSame( 870, Euro::newFromFloat( 8.70 )->getEuroCents() );
192
+		$this->assertSame(101, Euro::newFromFloat(1.0100000001)->getEuroCents());
193
+		$this->assertSame(101, Euro::newFromFloat(1.010000009999)->getEuroCents());
194
+		$this->assertSame(101, Euro::newFromFloat(1.011)->getEuroCents());
195
+		$this->assertSame(101, Euro::newFromFloat(1.014)->getEuroCents());
196
+		$this->assertSame(101, Euro::newFromFloat(1.0149)->getEuroCents());
197
+		$this->assertSame(102, Euro::newFromFloat(1.015)->getEuroCents());
198
+		$this->assertSame(102, Euro::newFromFloat(1.019)->getEuroCents());
199
+		$this->assertSame(102, Euro::newFromFloat(1.0199999)->getEuroCents());
200
+		$this->assertSame(870, Euro::newFromFloat(8.70)->getEuroCents());
201 201
 	}
202 202
 
203 203
 	public function testZeroEuroIntegers_isZeroCents() {
204
-		$this->assertSame( 0, Euro::newFromInt( 0 )->getEuroCents() );
204
+		$this->assertSame(0, Euro::newFromInt(0)->getEuroCents());
205 205
 	}
206 206
 
207 207
 	public function testOneEuroIntegers_is100cents() {
208
-		$this->assertSame( 100, Euro::newFromInt( 1 )->getEuroCents() );
208
+		$this->assertSame(100, Euro::newFromInt(1)->getEuroCents());
209 209
 	}
210 210
 
211 211
 	public function test1337EuroIntegers_is133700cents() {
212
-		$this->assertSame( 133700, Euro::newFromInt( 1337 )->getEuroCents() );
212
+		$this->assertSame(133700, Euro::newFromInt(1337)->getEuroCents());
213 213
 	}
214 214
 
215 215
 	public function testGivenNegativeIntegerAmount_exceptionIsThrown() {
216
-		$this->expectException( \InvalidArgumentException::class );
216
+		$this->expectException(\InvalidArgumentException::class);
217 217
 		Euro::newFromInt( -1 );
218 218
 	}
219 219
 
@@ -221,89 +221,89 @@  discard block
 block discarded – undo
221 221
 	 * @dataProvider euroProvider
222 222
 	 * @param Euro $euro
223 223
 	 */
224
-	public function testEuroEqualsItself( Euro $euro ) {
225
-		$this->assertTrue( $euro->equals( clone $euro ) );
224
+	public function testEuroEqualsItself(Euro $euro) {
225
+		$this->assertTrue($euro->equals(clone $euro));
226 226
 	}
227 227
 
228 228
 	public function euroProvider() {
229 229
 		return [
230
-			[ Euro::newFromCents( 0 ) ],
231
-			[ Euro::newFromCents( 1 ) ],
232
-			[ Euro::newFromCents( 99 ) ],
233
-			[ Euro::newFromCents( 100 ) ],
234
-			[ Euro::newFromCents( 9999 ) ],
230
+			[Euro::newFromCents(0)],
231
+			[Euro::newFromCents(1)],
232
+			[Euro::newFromCents(99)],
233
+			[Euro::newFromCents(100)],
234
+			[Euro::newFromCents(9999)],
235 235
 		];
236 236
 	}
237 237
 
238 238
 	public function testOneCentDoesNotEqualOneEuro() {
239
-		$this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromInt( 1 ) ) );
239
+		$this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromInt(1)));
240 240
 	}
241 241
 
242 242
 	public function testOneCentDoesNotEqualTwoCents() {
243
-		$this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromCents( 2 ) ) );
243
+		$this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromCents(2)));
244 244
 	}
245 245
 
246 246
 	public function testOneCentDoesNotEqualOneEuroAndOneCent() {
247
-		$this->assertFalse( Euro::newFromCents( 1 )->equals( Euro::newFromCents( 101 ) ) );
247
+		$this->assertFalse(Euro::newFromCents(1)->equals(Euro::newFromCents(101)));
248 248
 	}
249 249
 
250 250
 	public function test9001centsDoesNotEqual9000cents() {
251
-		$this->assertFalse( Euro::newFromCents( 9001 )->equals( Euro::newFromCents( 9000 ) ) );
251
+		$this->assertFalse(Euro::newFromCents(9001)->equals(Euro::newFromCents(9000)));
252 252
 	}
253 253
 
254 254
 	/**
255 255
 	 * @dataProvider tooLongStringProvider
256 256
 	 */
257
-	public function testNewFromStringThrowsExceptionWhenStringIsTooLong( string $string ) {
258
-		$this->expectException( InvalidArgumentException::class );
259
-		$this->expectExceptionMessage( 'Number is too big' );
257
+	public function testNewFromStringThrowsExceptionWhenStringIsTooLong(string $string) {
258
+		$this->expectException(InvalidArgumentException::class);
259
+		$this->expectExceptionMessage('Number is too big');
260 260
 
261
-		Euro::newFromString( $string );
261
+		Euro::newFromString($string);
262 262
 	}
263 263
 
264 264
 	public function tooLongStringProvider() {
265
-		yield [ '1111111111111111111111111111111' ];
266
-		yield [ (string)PHP_INT_MAX ];
267
-		yield [ substr( (string)PHP_INT_MAX, 0, -2 ) ];
265
+		yield ['1111111111111111111111111111111'];
266
+		yield [(string) PHP_INT_MAX];
267
+		yield [substr((string) PHP_INT_MAX, 0, -2)];
268 268
 	}
269 269
 
270 270
 	public function testNewFromStringHandlesLongStrings() {
271
-		Euro::newFromString( substr( (string)PHP_INT_MAX, 0, -3 ) );
272
-		$this->assertTrue( true );
271
+		Euro::newFromString(substr((string) PHP_INT_MAX, 0, -3));
272
+		$this->assertTrue(true);
273 273
 	}
274 274
 
275 275
 	/**
276 276
 	 * @dataProvider tooHighNumberProvider
277 277
 	 */
278
-	public function testNewFromIntThrowsExceptionWhenIntegerIsTooHigh( int $int ) {
279
-		$this->expectException( InvalidArgumentException::class );
280
-		$this->expectExceptionMessage( 'Number is too big' );
281
-		Euro::newFromInt( $int );
278
+	public function testNewFromIntThrowsExceptionWhenIntegerIsTooHigh(int $int) {
279
+		$this->expectException(InvalidArgumentException::class);
280
+		$this->expectExceptionMessage('Number is too big');
281
+		Euro::newFromInt($int);
282 282
 	}
283 283
 
284 284
 	public function tooHighNumberProvider() {
285
-		yield [ PHP_INT_MAX ];
286
-		yield [ PHP_INT_MAX / 10 ];
287
-		yield [ PHP_INT_MAX / 100 ];
285
+		yield [PHP_INT_MAX];
286
+		yield [PHP_INT_MAX / 10];
287
+		yield [PHP_INT_MAX / 100];
288 288
 	}
289 289
 
290 290
 	/**
291 291
 	 * @dataProvider tooHighNumberProvider
292 292
 	 */
293
-	public function testNewFromFloatThrowsExceptionWhenFloatIsTooHigh( int $int ) {
294
-		$this->expectException( InvalidArgumentException::class );
295
-		$this->expectExceptionMessage( 'Number is too big' );
296
-		Euro::newFromFloat( (float)$int );
293
+	public function testNewFromFloatThrowsExceptionWhenFloatIsTooHigh(int $int) {
294
+		$this->expectException(InvalidArgumentException::class);
295
+		$this->expectExceptionMessage('Number is too big');
296
+		Euro::newFromFloat((float) $int);
297 297
 	}
298 298
 
299 299
 	public function testNewFromIntHandlesBigIntegers() {
300 300
 		// Edge case test for the highest allowed value (Euro::CENTS_PER_EURO +1 )
301 301
 		// 100 (Euro::CENTS_PER_EURO) does not work due to rounding
302
-		$number = (int)floor( PHP_INT_MAX / 101 );
302
+		$number = (int) floor(PHP_INT_MAX / 101);
303 303
 
304 304
 		$this->assertSame(
305 305
 			$number * 100,
306
-			Euro::newFromInt( $number )->getEuroCents()
306
+			Euro::newFromInt($number)->getEuroCents()
307 307
 		);
308 308
 	}
309 309
 
Please login to merge, or discard this patch.
src/Euro.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,40 +49,40 @@  discard block
 block discarded – undo
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
-		if ( self::stringIsTooLong( $euroAmount ) ) {
58
-			throw new InvalidArgumentException( 'Number is too big' );
57
+		if (self::stringIsTooLong($euroAmount)) {
58
+			throw new InvalidArgumentException('Number is too big');
59 59
 		}
60 60
 
61
-		$parts = explode( '.', $euroAmount, 2 );
61
+		$parts = explode('.', $euroAmount, 2);
62 62
 
63
-		$euros = (int)$parts[0];
64
-		$cents = self::centsFromString( $parts[1] ?? '0' );
63
+		$euros = (int) $parts[0];
64
+		$cents = self::centsFromString($parts[1] ?? '0');
65 65
 
66
-		return new self( $euros * self::CENTS_PER_EURO + $cents );
66
+		return new self($euros * self::CENTS_PER_EURO + $cents);
67 67
 	}
68 68
 
69
-	private static function stringIsTooLong( string $euroString ): bool {
70
-		return strlen( $euroString ) + 2 > log10( PHP_INT_MAX );
69
+	private static function stringIsTooLong(string $euroString): bool {
70
+		return strlen($euroString) + 2 > log10(PHP_INT_MAX);
71 71
 	}
72 72
 
73
-	private static function centsFromString( string $cents ): int {
74
-		if ( strlen( $cents ) > self::DECIMAL_COUNT ) {
75
-			return self::roundCentsToInt( $cents );
73
+	private static function centsFromString(string $cents): int {
74
+		if (strlen($cents) > self::DECIMAL_COUNT) {
75
+			return self::roundCentsToInt($cents);
76 76
 		}
77 77
 
78 78
 		// Turn .1 into .10, so it ends up as 10 cents
79
-		return (int)str_pad( $cents, self::DECIMAL_COUNT, '0' );
79
+		return (int) str_pad($cents, self::DECIMAL_COUNT, '0');
80 80
 	}
81 81
 
82
-	private static function roundCentsToInt( string $cents ): int {
83
-		$centsInt = (int)substr( $cents, 0, self::DECIMAL_COUNT );
82
+	private static function roundCentsToInt(string $cents): int {
83
+		$centsInt = (int) substr($cents, 0, self::DECIMAL_COUNT);
84 84
 
85
-		if ( (int)$cents[self::DECIMAL_COUNT] >= 5 ) {
85
+		if ((int) $cents[self::DECIMAL_COUNT] >= 5) {
86 86
 			$centsInt++;
87 87
 		}
88 88
 
@@ -98,26 +98,26 @@  discard block
 block discarded – undo
98 98
 	 * @return self
99 99
 	 * @throws InvalidArgumentException
100 100
 	 */
101
-	public static function newFromFloat( float $euroAmount ): self {
102
-		self::assertMaximumValueNotExceeded( $euroAmount );
103
-		return new self( intval(
101
+	public static function newFromFloat(float $euroAmount): self {
102
+		self::assertMaximumValueNotExceeded($euroAmount);
103
+		return new self(intval(
104 104
 			round(
105
-				round( $euroAmount, self::DECIMAL_COUNT ) * self::CENTS_PER_EURO,
105
+				round($euroAmount, self::DECIMAL_COUNT) * self::CENTS_PER_EURO,
106 106
 				0
107 107
 			)
108
-		) );
108
+		));
109 109
 	}
110 110
 
111 111
 	/**
112 112
 	 * @param int|float $euroAmount
113 113
 	 */
114
-	private static function assertMaximumValueNotExceeded( $euroAmount ): void {
114
+	private static function assertMaximumValueNotExceeded($euroAmount): void {
115 115
 		// When $euroAmount == PHP_INT_MAX / self::CENTS_PER_EURO, multiplying it
116 116
 		// by self::CENTS_PER_EURO still exceeds PHP_INT_MAX, which leads type errors
117 117
 		// due to float conversion. The safest thing to do here is using a safety
118 118
 		// margin of 1 with self::CENTS_PER_EURO
119
-		if ( $euroAmount > floor( PHP_INT_MAX / ( self::CENTS_PER_EURO + 1 ) ) ) {
120
-			throw new InvalidArgumentException( 'Number is too big' );
119
+		if ($euroAmount > floor(PHP_INT_MAX / (self::CENTS_PER_EURO + 1))) {
120
+			throw new InvalidArgumentException('Number is too big');
121 121
 		}
122 122
 	}
123 123
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	 * @return self
127 127
 	 * @throws InvalidArgumentException
128 128
 	 */
129
-	public static function newFromInt( int $euroAmount ): self {
130
-		self::assertMaximumValueNotExceeded( $euroAmount );
131
-		return new self( $euroAmount * self::CENTS_PER_EURO );
129
+	public static function newFromInt(int $euroAmount): self {
130
+		self::assertMaximumValueNotExceeded($euroAmount);
131
+		return new self($euroAmount * self::CENTS_PER_EURO);
132 132
 	}
133 133
 
134 134
 	public function getEuroCents(): int {
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 	 * Returns the euro amount as string with two decimals always present in format "42.00".
144 144
 	 */
145 145
 	public function getEuroString(): string {
146
-		return number_format( $this->getEuroFloat(), self::DECIMAL_COUNT, '.', '' );
146
+		return number_format($this->getEuroFloat(), self::DECIMAL_COUNT, '.', '');
147 147
 	}
148 148
 
149
-	public function equals( Euro $euro ): bool {
149
+	public function equals(Euro $euro): bool {
150 150
 		return $this->cents === $euro->cents;
151 151
 	}
152 152
 
Please login to merge, or discard this patch.