Completed
Push — master ( c09113...29f456 )
by Walter
02:29
created
src/Notation.php 1 patch
Spacing   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -17,21 +17,21 @@  discard block
 block discarded – undo
17 17
  */
18 18
 final class Notation
19 19
 {
20
-    public const PIECE_PAWN = null;
21
-    public const PIECE_BISHOP = 'B';
22
-    public const PIECE_KING = 'K';
23
-    public const PIECE_KNIGHT = 'N';
24
-    public const PIECE_QUEEN = 'Q';
25
-    public const PIECE_ROOK = 'R';
20
+    public const PIECE_PAWN=null;
21
+    public const PIECE_BISHOP='B';
22
+    public const PIECE_KING='K';
23
+    public const PIECE_KNIGHT='N';
24
+    public const PIECE_QUEEN='Q';
25
+    public const PIECE_ROOK='R';
26 26
 
27
-    public const CASTLING_KING_SIDE = 'O-O';
28
-    public const CASTLING_QUEEN_SIDE = 'O-O-O';
27
+    public const CASTLING_KING_SIDE='O-O';
28
+    public const CASTLING_QUEEN_SIDE='O-O-O';
29 29
 
30
-    public const ANNOTATION_BLUNDER = '??';
31
-    public const ANNOTATION_MISTAKE = '?';
32
-    public const ANNOTATION_INTERESTING_MOVE = '?!';
33
-    public const ANNOTATION_GOOD_MOVE = '!';
34
-    public const ANNOTATION_BRILLIANT_MOVE = '!!';
30
+    public const ANNOTATION_BLUNDER='??';
31
+    public const ANNOTATION_MISTAKE='?';
32
+    public const ANNOTATION_INTERESTING_MOVE='?!';
33
+    public const ANNOTATION_GOOD_MOVE='!';
34
+    public const ANNOTATION_BRILLIANT_MOVE='!!';
35 35
 
36 36
     /**
37 37
      * The original value.
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function __construct(string $value)
135 135
     {
136
-        $this->value = $value;
137
-        $this->capture = false;
138
-        $this->check = false;
139
-        $this->checkmate = false;
140
-        $this->longSan = false;
136
+        $this->value=$value;
137
+        $this->capture=false;
138
+        $this->check=false;
139
+        $this->checkmate=false;
140
+        $this->longSan=false;
141 141
 
142 142
         $this->parse($value);
143 143
     }
@@ -152,188 +152,188 @@  discard block
 block discarded – undo
152 152
     {
153 153
         // Check for castling:
154 154
         if (preg_match('/^(O-O|O-O-O)(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
155
-            $this->castling = $matches[1];
156
-            $this->check = $matches[2] === '+';
157
-            $this->checkmate = $matches[2] === '#';
158
-            $this->annotation = isset($matches[3]) ? $matches[3] : null;
155
+            $this->castling=$matches[1];
156
+            $this->check=$matches[2] === '+';
157
+            $this->checkmate=$matches[2] === '#';
158
+            $this->annotation=isset($matches[3]) ? $matches[3] : null;
159 159
             return;
160 160
         }
161 161
 
162 162
         // Check for castling:
163 163
         if (preg_match('/^(0-0|0-0-0)(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
164
-            $this->castling = $matches[1];
165
-            $this->check = $matches[2] === '+';
166
-            $this->checkmate = $matches[2] === '#';
167
-            $this->annotation = isset($matches[3]) ? $matches[3] : null;
164
+            $this->castling=$matches[1];
165
+            $this->check=$matches[2] === '+';
166
+            $this->checkmate=$matches[2] === '#';
167
+            $this->annotation=isset($matches[3]) ? $matches[3] : null;
168 168
             return;
169 169
         }
170 170
 
171 171
         // Pawn movement:
172 172
         if (preg_match('/^([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
173
-            $this->targetColumn = $matches[1];
174
-            $this->targetRow = (int)$matches[2];
175
-            $this->check = $matches[3] === '+';
176
-            $this->checkmate = $matches[3] === '#';
177
-            $this->movedPiece = self::PIECE_PAWN;
178
-            $this->annotation = isset($matches[4]) ? $matches[4] : null;
173
+            $this->targetColumn=$matches[1];
174
+            $this->targetRow=(int) $matches[2];
175
+            $this->check=$matches[3] === '+';
176
+            $this->checkmate=$matches[3] === '#';
177
+            $this->movedPiece=self::PIECE_PAWN;
178
+            $this->annotation=isset($matches[4]) ? $matches[4] : null;
179 179
             return;
180 180
         }
181 181
 
182 182
         // Pawn movement (long san):
183 183
         if (preg_match('/^([a-h])([1-8])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
184
-            $this->movedPieceDisambiguationColumn = $matches[1];
185
-            $this->movedPieceDisambiguationRow = (int)$matches[2];
186
-            $this->targetColumn = $matches[3];
187
-            $this->targetRow = (int)$matches[4];
188
-            $this->check = $matches[5] === '+';
189
-            $this->checkmate = $matches[5] === '#';
190
-            $this->movedPiece = self::PIECE_PAWN;
191
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
192
-            $this->longSan = true;
184
+            $this->movedPieceDisambiguationColumn=$matches[1];
185
+            $this->movedPieceDisambiguationRow=(int) $matches[2];
186
+            $this->targetColumn=$matches[3];
187
+            $this->targetRow=(int) $matches[4];
188
+            $this->check=$matches[5] === '+';
189
+            $this->checkmate=$matches[5] === '#';
190
+            $this->movedPiece=self::PIECE_PAWN;
191
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
192
+            $this->longSan=true;
193 193
             return;
194 194
         }
195 195
 
196 196
         // Piece movement:
197 197
         if (preg_match('/^([KQBNR])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
198
-            $this->movedPiece = $matches[1];
199
-            $this->targetColumn = $matches[2];
200
-            $this->targetRow = (int)$matches[3];
201
-            $this->check = $matches[4] === '+';
202
-            $this->checkmate = $matches[4] === '#';
203
-            $this->annotation = isset($matches[5]) ? $matches[5] : null;
198
+            $this->movedPiece=$matches[1];
199
+            $this->targetColumn=$matches[2];
200
+            $this->targetRow=(int) $matches[3];
201
+            $this->check=$matches[4] === '+';
202
+            $this->checkmate=$matches[4] === '#';
203
+            $this->annotation=isset($matches[5]) ? $matches[5] : null;
204 204
             return;
205 205
         }
206 206
 
207 207
         // Piece movement from a specific column:
208 208
         if (preg_match('/^([KQBNR])([a-h])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
209
-            $this->movedPiece = $matches[1];
210
-            $this->movedPieceDisambiguationColumn = $matches[2];
211
-            $this->targetColumn = $matches[3];
212
-            $this->targetRow = (int)$matches[4];
213
-            $this->check = $matches[5] === '+';
214
-            $this->checkmate = $matches[5] === '#';
215
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
209
+            $this->movedPiece=$matches[1];
210
+            $this->movedPieceDisambiguationColumn=$matches[2];
211
+            $this->targetColumn=$matches[3];
212
+            $this->targetRow=(int) $matches[4];
213
+            $this->check=$matches[5] === '+';
214
+            $this->checkmate=$matches[5] === '#';
215
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
216 216
             return;
217 217
         }
218 218
 
219 219
         // Piece movement from a specific row:
220 220
         if (preg_match('/^([KQBNR])([0-9])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
221
-            $this->movedPiece = $matches[1];
222
-            $this->movedPieceDisambiguationRow = (int)$matches[2];
223
-            $this->targetColumn = $matches[3];
224
-            $this->targetRow = (int)$matches[4];
225
-            $this->check = $matches[5] === '+';
226
-            $this->checkmate = $matches[5] === '#';
227
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
221
+            $this->movedPiece=$matches[1];
222
+            $this->movedPieceDisambiguationRow=(int) $matches[2];
223
+            $this->targetColumn=$matches[3];
224
+            $this->targetRow=(int) $matches[4];
225
+            $this->check=$matches[5] === '+';
226
+            $this->checkmate=$matches[5] === '#';
227
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
228 228
             return;
229 229
         }
230 230
 
231 231
         // Piece movement from a specific column and row (long san):
232 232
         if (preg_match('/^([KQBNR])([a-h])([0-9])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
233
-            $this->movedPiece = $matches[1];
234
-            $this->movedPieceDisambiguationColumn = $matches[2];
235
-            $this->movedPieceDisambiguationRow = (int)$matches[3];
236
-            $this->targetColumn = $matches[4];
237
-            $this->targetRow = (int)$matches[5];
238
-            $this->check = $matches[6] === '+';
239
-            $this->checkmate = $matches[6] === '#';
240
-            $this->annotation = isset($matches[7]) ? $matches[7] : null;
241
-            $this->longSan = true;
233
+            $this->movedPiece=$matches[1];
234
+            $this->movedPieceDisambiguationColumn=$matches[2];
235
+            $this->movedPieceDisambiguationRow=(int) $matches[3];
236
+            $this->targetColumn=$matches[4];
237
+            $this->targetRow=(int) $matches[5];
238
+            $this->check=$matches[6] === '+';
239
+            $this->checkmate=$matches[6] === '#';
240
+            $this->annotation=isset($matches[7]) ? $matches[7] : null;
241
+            $this->longSan=true;
242 242
             return;
243 243
         }
244 244
 
245 245
         // Pawn capture:
246 246
         if (preg_match('/^([a-h])x([a-h])([1-8])(?:=?([KQBNR]))?(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
247
-            $this->targetColumn = $matches[2];
248
-            $this->targetRow = (int)$matches[3];
249
-            $this->movedPiece = self::PIECE_PAWN;
250
-            $this->movedPieceDisambiguationColumn = $matches[1];
251
-            $this->capture = true;
252
-            $this->promotedPiece = $matches[4] ?: null;
253
-            $this->check = $matches[5] === '+';
254
-            $this->checkmate = $matches[5] === '#';
255
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
247
+            $this->targetColumn=$matches[2];
248
+            $this->targetRow=(int) $matches[3];
249
+            $this->movedPiece=self::PIECE_PAWN;
250
+            $this->movedPieceDisambiguationColumn=$matches[1];
251
+            $this->capture=true;
252
+            $this->promotedPiece=$matches[4] ?: null;
253
+            $this->check=$matches[5] === '+';
254
+            $this->checkmate=$matches[5] === '#';
255
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
256 256
             return;
257 257
         }
258 258
 
259 259
         // Pawn capture (long san):
260 260
         if (preg_match('/^([a-h])([1-8])x([a-h])([1-8])(?:=?([KQBNR]))?(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
261
-            $this->targetColumn = $matches[3];
262
-            $this->targetRow = (int)$matches[4];
263
-            $this->movedPiece = self::PIECE_PAWN;
264
-            $this->movedPieceDisambiguationColumn = $matches[1];
265
-            $this->movedPieceDisambiguationRow = (int)$matches[2];
266
-            $this->capture = true;
267
-            $this->promotedPiece = $matches[5] ?: null;
268
-            $this->check = $matches[6] === '+';
269
-            $this->checkmate = $matches[6] === '#';
270
-            $this->annotation = isset($matches[7]) ? $matches[7] : null;
271
-            $this->longSan = true;
261
+            $this->targetColumn=$matches[3];
262
+            $this->targetRow=(int) $matches[4];
263
+            $this->movedPiece=self::PIECE_PAWN;
264
+            $this->movedPieceDisambiguationColumn=$matches[1];
265
+            $this->movedPieceDisambiguationRow=(int) $matches[2];
266
+            $this->capture=true;
267
+            $this->promotedPiece=$matches[5] ?: null;
268
+            $this->check=$matches[6] === '+';
269
+            $this->checkmate=$matches[6] === '#';
270
+            $this->annotation=isset($matches[7]) ? $matches[7] : null;
271
+            $this->longSan=true;
272 272
             return;
273 273
         }
274 274
 
275 275
         // Piece capture:
276 276
         if (preg_match('/^([KQBNR])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
277
-            $this->movedPiece = $matches[1];
278
-            $this->targetColumn = $matches[2];
279
-            $this->targetRow = (int)$matches[3];
280
-            $this->check = $matches[4] === '+';
281
-            $this->checkmate = $matches[4] === '#';
282
-            $this->capture = true;
283
-            $this->annotation = isset($matches[5]) ? $matches[5] : null;
277
+            $this->movedPiece=$matches[1];
278
+            $this->targetColumn=$matches[2];
279
+            $this->targetRow=(int) $matches[3];
280
+            $this->check=$matches[4] === '+';
281
+            $this->checkmate=$matches[4] === '#';
282
+            $this->capture=true;
283
+            $this->annotation=isset($matches[5]) ? $matches[5] : null;
284 284
             return;
285 285
         }
286 286
 
287 287
         // Piece capture from a specific column:
288 288
         if (preg_match('/^([KQBNR])([a-h])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
289
-            $this->movedPiece = $matches[1];
290
-            $this->movedPieceDisambiguationColumn = $matches[2];
291
-            $this->targetColumn = $matches[3];
292
-            $this->targetRow = (int)$matches[4];
293
-            $this->check = $matches[5] === '+';
294
-            $this->checkmate = $matches[5] === '#';
295
-            $this->capture = true;
296
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
289
+            $this->movedPiece=$matches[1];
290
+            $this->movedPieceDisambiguationColumn=$matches[2];
291
+            $this->targetColumn=$matches[3];
292
+            $this->targetRow=(int) $matches[4];
293
+            $this->check=$matches[5] === '+';
294
+            $this->checkmate=$matches[5] === '#';
295
+            $this->capture=true;
296
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
297 297
             return;
298 298
         }
299 299
 
300 300
         // Piece capture from a specific row:
301 301
         if (preg_match('/^([KQBNR])([0-9])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
302
-            $this->movedPiece = $matches[1];
303
-            $this->movedPieceDisambiguationRow = (int)$matches[2];
304
-            $this->targetColumn = $matches[3];
305
-            $this->targetRow = (int)$matches[4];
306
-            $this->check = $matches[5] === '+';
307
-            $this->checkmate = $matches[5] === '#';
308
-            $this->capture = true;
309
-            $this->annotation = isset($matches[6]) ? $matches[6] : null;
302
+            $this->movedPiece=$matches[1];
303
+            $this->movedPieceDisambiguationRow=(int) $matches[2];
304
+            $this->targetColumn=$matches[3];
305
+            $this->targetRow=(int) $matches[4];
306
+            $this->check=$matches[5] === '+';
307
+            $this->checkmate=$matches[5] === '#';
308
+            $this->capture=true;
309
+            $this->annotation=isset($matches[6]) ? $matches[6] : null;
310 310
             return;
311 311
         }
312 312
 
313 313
         // Piece capture from a specific column and row (long san):
314 314
         if (preg_match('/^([KQBNR])([a-h])([0-9])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
315
-            $this->movedPiece = $matches[1];
316
-            $this->movedPieceDisambiguationColumn = $matches[2];
317
-            $this->movedPieceDisambiguationRow = (int)$matches[3];
318
-            $this->targetColumn = $matches[4];
319
-            $this->targetRow = (int)$matches[5];
320
-            $this->check = $matches[6] === '+';
321
-            $this->checkmate = $matches[6] === '#';
322
-            $this->capture = true;
323
-            $this->annotation = isset($matches[7]) ? $matches[7] : null;
324
-            $this->longSan = true;
315
+            $this->movedPiece=$matches[1];
316
+            $this->movedPieceDisambiguationColumn=$matches[2];
317
+            $this->movedPieceDisambiguationRow=(int) $matches[3];
318
+            $this->targetColumn=$matches[4];
319
+            $this->targetRow=(int) $matches[5];
320
+            $this->check=$matches[6] === '+';
321
+            $this->checkmate=$matches[6] === '#';
322
+            $this->capture=true;
323
+            $this->annotation=isset($matches[7]) ? $matches[7] : null;
324
+            $this->longSan=true;
325 325
             return;
326 326
         }
327 327
 
328 328
         // Check for pawn promotion:
329 329
         if (preg_match('/^([a-h])([1-8])=?([KQBNR])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) {
330
-            $this->movedPiece = self::PIECE_PAWN;
331
-            $this->targetColumn = $matches[1];
332
-            $this->targetRow = (int)$matches[2];
333
-            $this->promotedPiece = $matches[3];
334
-            $this->check = $matches[4] === '+';
335
-            $this->checkmate = $matches[4] === '#';
336
-            $this->annotation = isset($matches[5]) ? $matches[5] : null;
330
+            $this->movedPiece=self::PIECE_PAWN;
331
+            $this->targetColumn=$matches[1];
332
+            $this->targetRow=(int) $matches[2];
333
+            $this->promotedPiece=$matches[3];
334
+            $this->check=$matches[4] === '+';
335
+            $this->checkmate=$matches[4] === '#';
336
+            $this->annotation=isset($matches[5]) ? $matches[5] : null;
337 337
             return;
338 338
         }
339 339
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             throw new RuntimeException('No row has been set.');
432 432
         }
433 433
 
434
-        $notation = chr(97 + $index) . $this->getTargetRow();
434
+        $notation=chr(97 + $index).$this->getTargetRow();
435 435
 
436 436
         return new self($notation);
437 437
     }
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      */
456 456
     public function withTargetRow(int $row): Notation
457 457
     {
458
-        $notation = $this->getTargetColumn() . $row;
458
+        $notation=$this->getTargetColumn().$row;
459 459
 
460 460
         return new self($notation);
461 461
     }
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     public function getTargetNotation(): string
469 469
     {
470
-        return $this->getTargetColumn() . $this->getTargetRow();
470
+        return $this->getTargetColumn().$this->getTargetRow();
471 471
     }
472 472
 
473 473
     /**
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
      */
498 498
     public function setMovedPieceDisambiguationColumn(?string $movedPieceDisambiguationColumn): void
499 499
     {
500
-        $this->movedPieceDisambiguationColumn = $movedPieceDisambiguationColumn;
500
+        $this->movedPieceDisambiguationColumn=$movedPieceDisambiguationColumn;
501 501
     }
502 502
 
503 503
     /**
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
      */
518 518
     public function setMovedPieceDisambiguationRow(?int $movedPieceDisambiguationRow): void
519 519
     {
520
-        $this->movedPieceDisambiguationRow = $movedPieceDisambiguationRow;
520
+        $this->movedPieceDisambiguationRow=$movedPieceDisambiguationRow;
521 521
     }
522 522
 
523 523
     /**
Please login to merge, or discard this patch.