code refactoring

- improved comparing & checking
- improved string composition
This commit is contained in:
Steffen Schröder
2014-06-14 14:32:29 +02:00
parent bd6e0b5151
commit 9985b814d2
41 changed files with 337 additions and 318 deletions

View File

@ -34,7 +34,7 @@ class MXMapInfo {
return;
}
if ($this->prefix == 'tm') {
if ($this->prefix === 'tm') {
$this->dir = 'tracks';
$this->id = $mx->TrackID;
$this->uid = isset($mx->TrackUID) ? $mx->TrackUID : '';
@ -44,7 +44,7 @@ class MXMapInfo {
$this->uid = isset($mx->MapUID) ? $mx->MapUID : '';
}
if (!isset($mx->GbxMapName) || $mx->GbxMapName == '?') {
if (!isset($mx->GbxMapName) || $mx->GbxMapName === '?') {
$this->name = $mx->Name;
} else {
$this->name = Formatter::stripDirtyCodes($mx->GbxMapName);
@ -84,9 +84,9 @@ class MXMapInfo {
$this->ratingVoteCount = isset($mx->RatingVoteCount) ? $mx->RatingVoteCount : 0;
$this->ratingVoteAverage = isset($mx->RatingVoteAverage) ? $mx->RatingVoteAverage : 0;
if ($this->trkvalue == 0 && $this->lbrating > 0) {
if (!$this->trkvalue && $this->lbrating > 0) {
$this->trkvalue = $this->lbrating;
} elseif ($this->lbrating == 0 && $this->trkvalue > 0) {
} elseif (!$this->lbrating && $this->trkvalue > 0) {
$this->lbrating = $this->trkvalue;
}
@ -105,7 +105,7 @@ class MXMapInfo {
$this->thumburl = '';
}
if ($this->prefix == 'tm' && $this->replayid > 0) {
if ($this->prefix === 'tm' && $this->replayid > 0) {
$this->replayurl = 'http://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid;
} else {
$this->replayurl = '';

View File

@ -108,21 +108,22 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$environment = '';
if (count($params) >= 1) {
foreach ($params as $param) {
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
if ($param === '/xlist' || $param === MapCommands::ACTION_OPEN_XLIST) {
continue;
}
if ($param == self::ACTION_SEARCH_MAPNAME) {
if ($param === self::ACTION_SEARCH_MAPNAME) {
$searchString = $chatCallback[1][3][0]['Value'];
} else if ($param == self::ACTION_SEARCH_AUTHOR) {
} else if ($param === self::ACTION_SEARCH_AUTHOR) {
$author = $chatCallback[1][3][0]['Value'];
} else if (strtolower(substr($param, 0, 5)) == 'auth:') {
} else if (strtolower(substr($param, 0, 5)) === 'auth:') {
$author = substr($param, 5);
} else if (strtolower(substr($param, 0, 4)) == 'env:') {
} else if (strtolower(substr($param, 0, 4)) === 'env:') {
$environment = substr($param, 4);
} else {
if ($searchString == '') {
if (!$searchString) {
$searchString = $param;
} else { // concatenate words in name
} else {
// concatenate words in name
$searchString .= '%20' . $param;
}
}
@ -192,7 +193,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$mapFrame = new Frame();
$pageFrame->add($mapFrame);
if ($i % 2 == 0) {
if ($i % 2 === 0) {
$lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
@ -201,7 +202,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
}
$time = Formatter::time_elapsed_string(strtotime($map->updated));
$array = array('$s' . $map->id => $x + 3.5, '$s' . $map->name => $x + 12.5, '$s' . $map->author => $x + 59, '$s' . str_replace("Arena", "", $map->maptype) => $x + 103, '$s' . $map->mood => $x + 118, '$s' . $time => $x + 130);
$array = array('$s' . $map->id => $x + 3.5, '$s' . $map->name => $x + 12.5, '$s' . $map->author => $x + 59, '$s' . str_replace('Arena', '', $map->maptype) => $x + 103, '$s' . $map->mood => $x + 118, '$s' . $time => $x + 130);
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
$authorLabel = $labels[2];
$authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
@ -337,7 +338,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
*/
public function handleWidgetOpened(Player $player, $openedWidget) {
//unset when another main widget got opened
if ($openedWidget != 'ManiaExchangeList') {
if ($openedWidget !== 'ManiaExchangeList') {
unset($this->mapListShown[$player->login]);
}
}

View File

@ -111,7 +111,7 @@ class ManiaExchangeManager {
//Set changed time into the map object
$map->lastUpdate = strtotime($changed);
if ($mxId != 0) {
if ($mxId) {
$appendString = $mxId . ',';
//Set the mx id to the mxidmapvektor
$this->mxIdUidVector[$mxId] = $map->uid;
@ -122,7 +122,7 @@ class ManiaExchangeManager {
$id++;
//If Max Maplimit is reached, or string gets too long send the request
if ($id % self::MAPS_PER_MX_FETCH == 0) {
if ($id % self::MAPS_PER_MX_FETCH === 0) {
$mapIdString = substr($mapIdString, 0, -1);
$this->getMaplistByMixedUidIdString($mapIdString);
$mapIdString = '';
@ -131,7 +131,7 @@ class ManiaExchangeManager {
$mapIdString .= $appendString;
}
if ($mapIdString != '') {
if ($mapIdString) {
$mapIdString = substr($mapIdString, 0, -1);
$this->getMaplistByMixedUidIdString($mapIdString);
}
@ -273,6 +273,8 @@ class ManiaExchangeManager {
return false;
}
// TODO: remove $env because it's not really used?
// Get Title Id
$titleId = $this->maniaControl->server->titleId;
$titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame();
@ -282,20 +284,20 @@ class ManiaExchangeManager {
$game = explode('@', $titleId);
$envNumber = $this->getEnvironment($game[0]);
if ($env != '' || $envNumber != -1) {
if ($env || $envNumber > -1) {
$url .= '&environments=' . $envNumber;
}
if ($name != '') {
if ($name) {
$url .= '&trackname=' . str_replace(" ", "%20", $name);
}
if ($author != '') {
if ($author) {
$url .= '&author=' . $author;
}
$url .= '&priord=' . $searchOrder;
$url .= '&limit=' . $maxMapsReturned;
if ($titlePrefix != "tm") {
if ($titlePrefix !== "tm") {
$url .= '&minexebuild=' . self::MIN_EXE_BUILD;
}