Skip to content

Commit

Permalink
Remove function return-by-reference
Browse files Browse the repository at this point in the history
See smrealms#317.

We have incrementally removed most usages of functions returning by
reference; therefore, we can now remove the ability to return by
reference for most functions.
  • Loading branch information
hemberger committed Jan 2, 2020
1 parent 3b9a2f4 commit 99887a7
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 117 deletions.
6 changes: 3 additions & 3 deletions lib/Default/AbstractSmrAccount.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function getDefaultHotkeys() {
return self::DEFAULT_HOTKEYS;
}

public static function &getAccount($accountID,$forceUpdate = false) {
public static function getAccount($accountID,$forceUpdate = false) {
if($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) {
self::$CACHE_ACCOUNTS[$accountID] = new SmrAccount($accountID);
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public function getScore() {
return $this->score;
}

public function &getIndividualScores(SmrPlayer $player = null) {
public function getIndividualScores(SmrPlayer $player = null) {
$gameID=0;
if($player!=null)
$gameID = $player->getGameID();
Expand Down Expand Up @@ -462,7 +462,7 @@ public function hasReferrer() {
return $this->referrerID>0;
}

public function &getReferrer() {
public function getReferrer() {
return SmrAccount::getAccount($this->getReferrerID());
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Default/AbstractSmrLocation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function clearCache() {
self::$CACHE_SECTOR_LOCATIONS = [];
}

public static function &getAllLocations($forceUpdate = false) {
public static function getAllLocations($forceUpdate = false) {
if ($forceUpdate || !isset(self::$CACHE_ALL_LOCATIONS)) {
$db = new SmrMySqlDatabase();
$db->query('SELECT * FROM location_type ORDER BY location_type_id');
Expand Down Expand Up @@ -60,7 +60,7 @@ public static function getGalaxyLocations($gameID, $galaxyID, $forceUpdate = fal
return $galaxyLocations;
}

public static function &getSectorLocations($gameID, $sectorID, $forceUpdate = false) {
public static function getSectorLocations($gameID, $sectorID, $forceUpdate = false) {
if ($forceUpdate || !isset(self::$CACHE_SECTOR_LOCATIONS[$gameID][$sectorID])) {
$db = new SmrMySqlDatabase();
$db->query('SELECT * FROM location JOIN location_type USING (location_type_id) WHERE sector_id = ' . $db->escapeNumber($sectorID) . ' AND game_id=' . $db->escapeNumber($gameID));
Expand All @@ -74,7 +74,7 @@ public static function &getSectorLocations($gameID, $sectorID, $forceUpdate = fa
return self::$CACHE_SECTOR_LOCATIONS[$gameID][$sectorID];
}

public static function &getLocation($locationTypeID, $forceUpdate = false, $db = null) {
public static function getLocation($locationTypeID, $forceUpdate = false, $db = null) {
if ($forceUpdate || !isset(self::$CACHE_LOCATIONS[$locationTypeID])) {
self::$CACHE_LOCATIONS[$locationTypeID] = new SmrLocation($locationTypeID, $db);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public function setUG($bool) {
}
}

public function &getHardwareSold() {
public function getHardwareSold() {
if (!isset($this->hardwareSold)) {
$this->hardwareSold = array();
$this->db->query('SELECT hardware_type_id FROM location_sells_hardware WHERE ' . $this->SQL);
Expand Down Expand Up @@ -285,7 +285,7 @@ public function removeHardwareSold($hardwareTypeID) {
unset($this->hardwareSold[$hardwareTypeID]);
}

public function &getShipsSold() {
public function getShipsSold() {
if (!isset($this->shipsSold)) {
$this->shipsSold = array();
$this->db->query('SELECT * FROM location_sells_ships WHERE ' . $this->SQL);
Expand Down Expand Up @@ -320,7 +320,7 @@ public function removeShipSold($shipTypeID) {
unset($this->shipsSold[$shipTypeID]);
}

public function &getWeaponsSold() {
public function getWeaponsSold() {
if (!isset($this->weaponsSold)) {
$this->weaponsSold = array();
$this->db->query('SELECT * FROM location_sells_weapons JOIN weapon_type USING (weapon_type_id) WHERE ' . $this->SQL);
Expand Down Expand Up @@ -354,7 +354,7 @@ public function removeWeaponSold($weaponTypeID) {
unset($this->weaponsSold[$weaponTypeID]);
}

public function &getLinkedLocations() {
public function getLinkedLocations() {
$linkedLocations = array();
if ($this->isHQ()) {
if ($this->getTypeID() == LOCATION_TYPE_FEDERAL_HQ) {
Expand Down
12 changes: 6 additions & 6 deletions lib/Default/AbstractSmrPlayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getGameID() {
return $this->gameID;
}

public function &getGame() {
public function getGame() {
return SmrGame::getGame($this->gameID);
}

Expand Down Expand Up @@ -106,19 +106,19 @@ public function getPlanet() {
}
}

public function &getSectorPlanet() {
public function getSectorPlanet() {
return SmrPlanet::getPlanet($this->getGameID(), $this->getSectorID());
}

public function &getSectorPort() {
public function getSectorPort() {
return SmrPort::getPort($this->getGameID(), $this->getSectorID());
}

public function getSectorID() {
return $this->sectorID;
}

public function &getSector() {
public function getSector() {
return SmrSector::getSector($this->getGameID(), $this->getSectorID());
}

Expand Down Expand Up @@ -522,7 +522,7 @@ public function isAllianceLeader($forceUpdate = false) {
return $this->getAccountID() == $this->getAlliance($forceUpdate)->getLeaderID();
}

public function &getAlliance($forceUpdate = false) {
public function getAlliance($forceUpdate = false) {
return SmrAlliance::getAlliance($this->getAllianceID(), $this->getGameID(), $forceUpdate);
}

Expand Down Expand Up @@ -625,7 +625,7 @@ public function getRelation($raceID) {
return $rels[$raceID];
}

abstract public function &getShip();
abstract public function getShip();

public function &shootPlayer(AbstractSmrPlayer $targetPlayer) {
return $this->getShip()->shootPlayer($targetPlayer);
Expand Down
20 changes: 10 additions & 10 deletions lib/Default/AbstractSmrPort.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function getGalaxyPorts($gameID, $galaxyID, $forceUpdate = false)
return $galaxyPorts;
}

public static function &getPort($gameID, $sectorID, $forceUpdate = false, $db = null) {
public static function getPort($gameID, $sectorID, $forceUpdate = false, $db = null) {
if ($forceUpdate || !isset(self::$CACHE_PORTS[$gameID][$sectorID])) {
self::$CACHE_PORTS[$gameID][$sectorID] = new SmrPort($gameID, $sectorID, $db);
}
Expand All @@ -104,7 +104,7 @@ public static function removePort($gameID, $sectorID) {
unset(self::$CACHE_PORTS[$gameID][$sectorID]);
}

public static function &createPort($gameID, $sectorID) {
public static function createPort($gameID, $sectorID) {
if (!isset(self::$CACHE_PORTS[$gameID][$sectorID])) {
$p = new SmrPort($gameID, $sectorID);
self::$CACHE_PORTS[$gameID][$sectorID] = $p;
Expand Down Expand Up @@ -263,25 +263,25 @@ public function getVisibleGoodsBought(AbstractSmrPlayer $player = null) {
return $this->getVisibleGoods('Buy', $player);
}

public function &getAllGoodIDs() {
public function getAllGoodIDs() {
return $this->goodIDs['All'];
}

/**
* Get IDs of goods that can be sold to the port
*/
public function &getSoldGoodIDs() {
public function getSoldGoodIDs() {
return $this->goodIDs['Sell'];
}

/**
* Get IDs of goods that can be bought from the port
*/
public function &getBoughtGoodIDs() {
public function getBoughtGoodIDs() {
return $this->goodIDs['Buy'];
}

public function &getGood($goodID) {
public function getGood($goodID) {
if ($this->hasGood($goodID)) {
return Globals::getGood($goodID);
} else {
Expand Down Expand Up @@ -795,7 +795,7 @@ public function getSectorID() {
return $this->sectorID;
}

public function &getSector() {
public function getSector() {
return SmrSector::getSector($this->getGameID(), $this->getSectorID());
}

Expand Down Expand Up @@ -866,7 +866,7 @@ public function getNumWeapons() {
return $this->getLevel() + 3;
}

public function &getWeapons() {
public function getWeapons() {
$weapons = array();
for ($i = 0; $i < $this->getNumWeapons(); ++$i) {
$weapons[$i] = SmrWeapon::getWeapon(WEAPON_PORT_TURRET);
Expand Down Expand Up @@ -1093,7 +1093,7 @@ public function addCachePorts(array $accountIDs) {
}
return false;
}
public static function &getCachedPort($gameID, $sectorID, $accountID, $forceUpdate = false) {
public static function getCachedPort($gameID, $sectorID, $accountID, $forceUpdate = false) {
if ($forceUpdate || !isset(self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID])) {
$db = new SmrMySqlDatabase();
$db->query('SELECT visited, port_info
Expand Down Expand Up @@ -1275,7 +1275,7 @@ protected function doArmourDamage($damage) {
return $actualDamage;
}

protected function &getAttackersToCredit() {
protected function getAttackersToCredit() {
//get all players involved for HoF
$attackers = array();
$this->db->query('SELECT account_id FROM player_attacks_port WHERE ' . $this->SQL . ' AND time > ' . $this->db->escapeNumber(TIME - self::TIME_TO_CREDIT_RAID));
Expand Down
14 changes: 7 additions & 7 deletions lib/Default/AbstractSmrShip.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractSmrShip {
protected $hasChangedCargo = false;
protected $hasChangedHardware = array();

public static function &getBaseShip($gameTypeID, $shipTypeID, $forceUpdate = false) {
public static function getBaseShip($gameTypeID, $shipTypeID, $forceUpdate = false) {
if ($forceUpdate || !isset(self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID])) {
// determine ship
$db = new SmrMySqlDatabase();
Expand All @@ -42,7 +42,7 @@ public static function &getBaseShip($gameTypeID, $shipTypeID, $forceUpdate = fal
return self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID];
}

protected static function &buildBaseShip(MySqlDatabase $db) {
protected static function buildBaseShip(MySqlDatabase $db) {
$ship = array();
$ship['Type'] = 'Ship';
$ship['Name'] = $db->getField('ship_name');
Expand Down Expand Up @@ -114,7 +114,7 @@ protected static function &buildBaseShip(MySqlDatabase $db) {
return $ship;
}

public static function &getAllBaseShips($gameTypeID, $forceUpdate = false) {
public static function getAllBaseShips($gameTypeID, $forceUpdate = false) {
// determine ship
$db = new SmrMySqlDatabase();
$db->query('SELECT * FROM ship_type ORDER BY ship_type_id ASC'); //TODO add game type id
Expand Down Expand Up @@ -249,7 +249,7 @@ public function getCDsHigh() : int { return $this->getCDsLow() + 100; }



public function &addWeapon($weaponTypeID) {
public function addWeapon($weaponTypeID) {
if ($this->hasOpenWeaponSlots() && $this->hasRemainingPower()) {
$weapon = SmrWeapon::getWeapon($weaponTypeID);
if ($this->getRemainingPower() >= $weapon->getPowerLevel()) {
Expand Down Expand Up @@ -431,7 +431,7 @@ public function getIllusionDefense() {
return $this->illusionShip['Defense'];
}

public function &getPlayer() {
public function getPlayer() {
return $this->player;
}

Expand Down Expand Up @@ -735,7 +735,7 @@ public function setCargoHolds($amount) {
$this->setHardware(HARDWARE_CARGO, $amount);
}

public function &getCargo($goodID = false) {
public function getCargo($goodID = false) {
if ($goodID !== false) {
if (isset($this->cargo[$goodID]))
return $this->cargo[$goodID];
Expand Down Expand Up @@ -813,7 +813,7 @@ public function hasWeapons() {
return $this->getNumWeapons() > 0;
}

public function &getWeapons() {
public function getWeapons() {
return $this->weapons;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Default/ChessGame.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChessGame {

private $lastMove = null;

public static function &getNPCMoveGames($forceUpdate = false) {
public static function getNPCMoveGames($forceUpdate = false) {
$db = new SmrMySqlDatabase();
$db->query('SELECT chess_game_id
FROM npc_logins
Expand All @@ -42,7 +42,7 @@ public static function &getNPCMoveGames($forceUpdate = false) {
return $games;
}

public static function &getOngoingPlayerGames(AbstractSmrPlayer $player) {
public static function getOngoingPlayerGames(AbstractSmrPlayer $player) {
$db = new SmrMySqlDatabase();
$db->query('SELECT chess_game_id FROM chess_game WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND (black_id = ' . $db->escapeNumber($player->getAccountID()) . ' OR white_id = ' . $db->escapeNumber($player->getAccountID()) . ') AND (end_time > ' . TIME . ' OR end_time IS NULL);');
$games = array();
Expand All @@ -52,7 +52,7 @@ public static function &getOngoingPlayerGames(AbstractSmrPlayer $player) {
return $games;
}

public static function &getAccountGames($accountID) {
public static function getAccountGames($accountID) {
$db = new SmrMySqlDatabase();
$db->query('SELECT chess_game_id FROM chess_game WHERE black_id = ' . $db->escapeNumber($accountID) . ' OR white_id = ' . $db->escapeNumber($accountID) . ';');
$games = array();
Expand All @@ -62,7 +62,7 @@ public static function &getAccountGames($accountID) {
return $games;
}

public static function &getChessGame($chessGameID,$forceUpdate = false) {
public static function getChessGame($chessGameID,$forceUpdate = false) {
if($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) {
self::$CACHE_CHESS_GAMES[$chessGameID] = new ChessGame($chessGameID);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Default/Council.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected static function initialiseDatabase() {
/**
* Returns an array of Account ID's of the Council for this race.
*/
public static function &getRaceCouncil($gameID, $raceID) {
public static function getRaceCouncil($gameID, $raceID) {
if (!isset(self::$COUNCILS[$gameID][$raceID])) {
self::initialiseDatabase();
self::$COUNCILS[$gameID][$raceID] = array();
Expand Down
2 changes: 1 addition & 1 deletion lib/Default/Distance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getEndSectorID() {
return $this->path[count($this->path) - 1];
}

public function &getEndSector() {
public function getEndSector() {
return SmrSector::getSector($this->gameID, $this->getEndSectorID());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Default/DummyPlayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function &killPlayerByPort(SmrPort $port) {
public function &killPlayerByPlanet(SmrPlanet $planet) {
}

public function &getShip() {
public function getShip() {
return DummyShip::getCachedDummyShip($this);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Default/DummyShip.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function cacheDummyShip() {
unserialize($cache);
}

public static function &getCachedDummyShip(AbstractSmrPlayer $player) {
public static function getCachedDummyShip(AbstractSmrPlayer $player) {
if(!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) {
$db = new SmrMySqlDatabase();
$db->query('SELECT info FROM cached_dummys
Expand All @@ -80,7 +80,7 @@ public static function &getCachedDummyShip(AbstractSmrPlayer $player) {
return self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()];
}

public static function &getDummyShipNames() {
public static function getDummyShipNames() {
$db = new SmrMySqlDatabase();
$db->query('SELECT id FROM cached_dummys
WHERE type = \'DummyShip\'');
Expand Down
Loading

0 comments on commit 99887a7

Please sign in to comment.