From 83efc941079cb0c95d88a9a1f7724210fadd16ba Mon Sep 17 00:00:00 2001 From: DHTMLGoodies Date: Wed, 22 Feb 2017 18:15:12 +0100 Subject: [PATCH] Gracefully skiping games the parser don't understand --- GameParser.php | 1 + PgnParser.php | 8 +++++++- test/ParserTest.php | 11 +++++++++++ test/pgn/art_attack.pgn | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 test/pgn/art_attack.pgn diff --git a/GameParser.php b/GameParser.php index 8b51db9..4ee75ee 100755 --- a/GameParser.php +++ b/GameParser.php @@ -52,6 +52,7 @@ class GameParser private function parseVariations(&$variations) { + foreach ($variations as &$variation) { $fen = $this->fenParser0x88->getFen(); $this->parseMoves($variation); diff --git a/PgnParser.php b/PgnParser.php index 4d5a5db..94ea815 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -160,7 +160,13 @@ class PgnParser $games = $this->getUnparsedGames(); $ret = array(); for ($i = 0, $count = count($games); $i < $count; $i++) { - $ret[] = $this->getParsedGame($games[$i]); + try{ + $g = $this->getParsedGame($games[$i]); + $ret[] = $g; + + }catch(Exception $e){ + + } } return $ret; } diff --git a/test/ParserTest.php b/test/ParserTest.php index cc928fb..c5cfce3 100755 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -2140,4 +2140,15 @@ Rc8 Ne6+ 72. Kf6 d2 73. c5+ Kd7 0-1'; return new FenParser0x88($fen); } + + /** + * @test + */ + public function shouldParseArtAttack(){ + $pgnParser = new PgnParser("pgn/art_attack.pgn"); + + // when + $game = $pgnParser->getGames(); + + } } diff --git a/test/pgn/art_attack.pgn b/test/pgn/art_attack.pgn new file mode 100755 index 0000000..e150869 --- /dev/null +++ b/test/pgn/art_attack.pgn @@ -0,0 +1,37 @@ +[Event "022 Art of Attack"] +[Site "?"] +[Date "????.??.??"] +[Round "?"] +[White "Smyslow"] +[Black "Florian"] +[Result "1-0"] +[SetUp "1"] +[FEN "r3r3/pp3pkp/n5p1/q1pP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