Skip to content

Commit 00e92a0

Browse files
committed
Upgraded to PHP 7.4
1 parent ab5c886 commit 00e92a0

6 files changed

Lines changed: 31 additions & 27 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"type": "library",
66
"require": {
7-
"php": "^7.2"
7+
"php": "^7.4"
88
},
99
"require-dev": {
1010
"chesszebra/coding-standards": "dev-master",

src/CastlingAvailability.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ChessZebra\ForsythEdwardsNotation;
66

77
use ChessZebra\ForsythEdwardsNotation\Exception\InvalidCastlingAvailabilityException;
8+
89
use function strlen;
910

1011
/**
@@ -44,10 +45,8 @@ final class CastlingAvailability
4445

4546
/**
4647
* The bitwise value that represents the castling availability.
47-
*
48-
* @var int
4948
*/
50-
private $value;
49+
private int $value;
5150

5251
/**
5352
* Initializes a new instance of this class.

src/Exception/InvalidCastlingAvailabilityException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use RuntimeException;
88
use Throwable;
9+
910
use function sprintf;
1011

1112
final class InvalidCastlingAvailabilityException extends RuntimeException // phpcs:ignore

src/Exception/InvalidFenException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use RuntimeException;
88
use Throwable;
9+
910
use function count;
1011
use function explode;
1112
use function sprintf;

src/FenNotation.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ChessZebra\ForsythEdwardsNotation;
66

77
use ChessZebra\ForsythEdwardsNotation\Exception\InvalidFenException;
8+
89
use function explode;
910

1011
/**
@@ -17,18 +18,14 @@ final class FenNotation
1718

1819
/**
1920
* The places of the pieces.
20-
*
21-
* @var string
2221
*/
23-
private $piecePlacement;
22+
private string $piecePlacement;
2423

2524
/**
2625
* An indication whether its black or white's turn.
2726
* The value 'b' means black, 'w' means white.
28-
*
29-
* @var string
3027
*/
31-
private $turn;
28+
private string $turn;
3229

3330
/**
3431
* A value that indicates whether or not castling is available.
@@ -37,35 +34,27 @@ final class FenNotation
3734
* - "Q" (White can castle queenside),
3835
* - "k" (Black can castle kingside), and/or
3936
* - "q" (Black can castle queenside).
40-
*
41-
* @var CastlingAvailability
4237
*/
43-
private $castlingAvailability;
38+
private CastlingAvailability $castlingAvailability;
4439

4540
/**
4641
* En passant target square in Standard Algebraic Notation (SAN).
4742
* If there's no en passant target square, this value is null. If a pawn has just made a two-square move, this is
4843
* the position "behind" the pawn. This is recorded regardless of whether there is a pawn in position to make an
4944
* en passant capture.
50-
*
51-
* @var string|null
5245
*/
53-
private $enPassantTargetSquare;
46+
private ?string $enPassantTargetSquare;
5447

5548
/**
5649
* Halfmove clock: This is the number of halfmoves since the last capture or pawn advance. This is used to
5750
* determine if a draw can be claimed under the fifty-move rule.
58-
*
59-
* @var int
6051
*/
61-
private $halfMoveClock;
52+
private int $halfMoveClock;
6253

6354
/**
6455
* Fullmove number: The number of the full move. It starts at 1, and is incremented after Black's move.
65-
*
66-
* @var int
6756
*/
68-
private $fullMoveNumber;
57+
private int $fullMoveNumber;
6958

7059
public function __construct(string $fen)
7160
{
@@ -91,29 +80,39 @@ private function validate(string $fen): void
9180

9281
case ValidationResult::EN_PASSANT_INVALID_MOVE:
9382
throw InvalidFenException::enPassantIllegal($fen);
83+
9484
case ValidationResult::EN_PASSANT_INVALID_SQUARE:
9585
throw InvalidFenException::enPassantInvalidSquare($fen);
86+
9687
case ValidationResult::FIELD_COUNT_TOO_LARGE:
9788
case ValidationResult::FIELD_COUNT_TOO_SMALL:
9889
throw InvalidFenException::incorrectFieldCount($fen);
90+
9991
case ValidationResult::INVALID_CASTLING_PIECE:
10092
throw InvalidFenException::invalidCastlingPiece($fen);
93+
10194
case ValidationResult::INVALID_TURN:
10295
throw InvalidFenException::invalidTurn($fen);
96+
10397
case ValidationResult::HALFMOVE_COUNTER_NAN:
10498
throw InvalidFenException::wrongHalfMoveCounter($fen);
99+
105100
case ValidationResult::MOVE_NUMBER_NAN:
106101
case ValidationResult::MOVE_NUMBER_POSITIVE:
107102
throw InvalidFenException::wrongMoveNumber($fen);
103+
108104
case ValidationResult::PIECE_CONSECUTIVE_NUMBERS:
109105
case ValidationResult::PIECE_INVALID:
110106
throw InvalidFenException::invalidPiecePlacement($fen);
107+
111108
case ValidationResult::PIECE_ROW_TOO_LARGE:
112109
case ValidationResult::PIECE_ROW_TOO_SMALL:
113110
throw InvalidFenException::incorrectPiecePlacementRowLength($fen);
111+
114112
case ValidationResult::PIECE_NOT_ENOUGH_ROWS:
115113
case ValidationResult::PIECE_TOO_MANY_ROWS:
116114
throw InvalidFenException::incorrectPiecePlacementRowsLength($fen);
115+
117116
default:
118117
throw InvalidFenException::unepectedError($fen); // @codeCoverageIgnore
119118
}

src/Validator.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public function validate(string $fen): int
6767
$previousWasNumber = false;
6868

6969
for ($k = 0; $k < strlen($rows[$i]); ++$k) {
70-
if (ctype_digit($rows[$i]{$k})) {
70+
if (ctype_digit($rows[$i][$k])) {
7171
if ($previousWasNumber) {
7272
return ValidationResult::PIECE_CONSECUTIVE_NUMBERS;
7373
}
7474

75-
$sumFields += intval($rows[$i]{$k}, 10);
75+
$sumFields += intval($rows[$i][$k], 10);
7676
$previousWasNumber = true;
7777
} else {
78-
if (strpos(self::SYMBOLS, $rows[$i]{$k}) === false) {
78+
if (strpos(self::SYMBOLS, $rows[$i][$k]) === false) {
7979
return ValidationResult::PIECE_INVALID;
8080
}
8181

@@ -94,8 +94,12 @@ public function validate(string $fen): int
9494
}
9595

9696
if ($tokens[FenFields::EN_PASSANT] !== '-') {
97-
if (($tokens[FenFields::EN_PASSANT]{1} === '3' && $tokens[FenFields::TURN] === 'w') ||
98-
($tokens[FenFields::EN_PASSANT]{1} === '6' && $tokens[FenFields::TURN] === 'b')) {
97+
$enPassant = $tokens[FenFields::EN_PASSANT];
98+
99+
if (
100+
($enPassant[1] === '3' && $tokens[FenFields::TURN] === 'w') ||
101+
($enPassant[1] === '6' && $tokens[FenFields::TURN] === 'b')
102+
) {
99103
return ValidationResult::EN_PASSANT_INVALID_MOVE;
100104
}
101105
}

0 commit comments

Comments
 (0)