From bd2a00ef46ff15d15296952e0a5eedd692f553e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Fri, 9 May 2014 13:00:13 +0200 Subject: [PATCH] improved path methods --- application/core/Players/Player.php | 45 +++++++++++++---------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index 1371cc2d..58bcb81a 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -153,50 +153,45 @@ class Player { * @return string */ public function getProvince() { - $pathParts = explode('|', $this->path); - if (isset($pathParts[3])) { - return $pathParts[3]; - } - return $this->getCountry(); + return $this->getPathPart(3); } /** - * Get country + * Get Country * * @return string */ public function getCountry() { - $pathParts = explode('|', $this->path); - if (isset($pathParts[2])) { - return $pathParts[2]; - } - if (isset($pathParts[1])) { - return $pathParts[1]; - } - if (isset($pathParts[0])) { - return $pathParts[0]; - } - return $this->path; + return $this->getPathPart(2); } /** - * Get continent + * Get Continent * * @return string */ public function getContinent() { + return $this->getPathPart(1); + } + + /** + * Get the specified Part of the Path + * + * @param int $partNumber + * @return string + */ + public function getPathPart($partNumber) { $pathParts = explode('|', $this->path); - if (isset($pathParts[1])) { - return $pathParts[1]; - } - if (isset($pathParts[0])) { - return $pathParts[0]; + for ($partIndex = $partNumber; $partIndex >= 0; $partIndex--) { + if (isset($pathParts[$partIndex])) { + return $pathParts[$partIndex]; + } } return $this->path; } /** - * Updates the Flags of the Player + * Update the Flags of the Player * * @param $flags */ @@ -214,7 +209,7 @@ class Player { } /** - * Updates the Spectator Status of the player + * Update the Spectator Status of the player * * @param $spectatorStatus */