From 8708b00cf7a350f113f506e5c51df495ea08b08b Mon Sep 17 00:00:00 2001 From: DHTMLGoodies Date: Fri, 18 Jan 2013 14:38:50 +0100 Subject: [PATCH] Code cleanup --- FenParser0x88.php | 23 ++++++----------------- PgnGameParser.php | 1 - test/ParserTest.php | 7 ++++++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/FenParser0x88.php b/FenParser0x88.php index 1d1fceb..18cc808 100644 --- a/FenParser0x88.php +++ b/FenParser0x88.php @@ -48,13 +48,11 @@ class FenParser0x88 } /** - * Return long notation for a move - * @method getLongNotationForAMove - * @param {Object} move - * @param {String} shortNotation - * @return {String} long notation - */ - public function getLongNotationForAMove($move, $shortNotation) { + * @param array $move + * @param bool $shortNotation + * @return string + */ + public function getLongNotationForAMove($move, $shortNotation) { if (strstr($shortNotation, 'O-')) { return $shortNotation; } @@ -127,7 +125,6 @@ class FenParser0x88 $pos += intval($token); } } - } public function getPieceOnSquare($square) { @@ -176,11 +173,7 @@ class FenParser0x88 function getEnPassantSquare() { - $enPassant = $this->fenParts['enPassant']; - if ($enPassant != '-') { - return $enPassant; - } - return null; + return ($this->fenParts['enPassant'] != '-') ? $this->fenParts['enPassant'] : null; } private function setEnPassantSquare($square) @@ -570,11 +563,9 @@ class FenParser0x88 $pinning = ''; while ($square !== $king['s'] && $countOpposite < 2) { $squares[] = $square; - if ($this->cache['board'][$square]) { $countOpposite++; if ((!$WHITE && $this->cache['board'][$square] & 0x8) || ($WHITE && !($this->cache['board'][$square] & 0x8))) { - $pinning = $square; } else { break; @@ -1294,9 +1285,7 @@ class FenParser0x88 if ($this->isEnPassantMove($move) || $this->cache['board'][$move['to']]) { $ret += Board0x88Config::$fileMapping[$move['from'] & 15] + 'x'; } - $ret += Board0x88Config::$fileMapping[$move['to'] & 15] + '' + Board0x88Config::$rankMapping[$move['to'] & 240]; - if (isset($move['promoteTo']) && $move['promoteTo']) { $numType = Board0x88Config::$typeToNumberMapping[$move['promoteTo']]; $ret .= '=' . Board0x88Config::$notationMapping[$numType]; diff --git a/PgnGameParser.php b/PgnGameParser.php index 8436ec0..5c9bb22 100644 --- a/PgnGameParser.php +++ b/PgnGameParser.php @@ -64,7 +64,6 @@ class PgnGameParser{ if($i==0){ $this->moveBuilder->addCommentBeforeFirstMove($parts[$i+1]); }else{ - $this->moveBuilder->addComment($parts[$i+1]); } $i+=2; diff --git a/test/ParserTest.php b/test/ParserTest.php index 60e81c2..201dfaa 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -25,7 +25,7 @@ class ParserTest extends PHPUnit_Framework_TestCase /** * @test */ - public function shouldCreatParser() + public function shouldCreateParser() { // given $parser = $this->getParser(); @@ -1796,6 +1796,11 @@ class ParserTest extends PHPUnit_Framework_TestCase } return $ret; } + + /** + * @param null $fen + * @return FenParser0x88 + */ private function getParser($fen = null) { if (!isset($fen)) {