Skip to content

Commit

Permalink
Remove references from class method arguments
Browse files Browse the repository at this point in the history
Arguments should only be passed by reference into a function if
the function intends to modify the original variable. It should
not be used to try to improve performance (it won't: see smrealms#317).

Here we remove improper references from class method arguments,
along with a few other internal references that I missed earlier.
  • Loading branch information
hemberger committed Apr 1, 2018
1 parent 55ebc63 commit 6a860d8
Show file tree
Hide file tree
Showing 22 changed files with 277 additions and 277 deletions.
16 changes: 8 additions & 8 deletions lib/Default/AbstractSmrAccount.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ abstract class AbstractSmrAccount {
return self::getAccountByName($login);
}

public static function getUserScoreCaseStatement(&$db) {
public static function getUserScoreCaseStatement($db) {
$userRankingTypes = array();
$case = 'FLOOR(SUM(CASE type ';
foreach(self::$USER_RANKINGS_SCORE as $userRankingScore) {
Expand Down Expand Up @@ -437,7 +437,7 @@ abstract class AbstractSmrAccount {
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 @@ -526,7 +526,7 @@ abstract class AbstractSmrAccount {
$credits+=$rewardCredits;
$rewardCredits=0;
}
if($this->credits==0&&$this->rewardCredits==0)
if($this->credits==0 && $this->rewardCredits==0)
$this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')');
else
$this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1');
Expand All @@ -547,7 +547,7 @@ abstract class AbstractSmrAccount {
public function setSmrCredits($credits) {
if($this->getSmrCredits()==$credits)
return;
if($this->credits==0&&$this->rewardCredits==0)
if($this->credits==0 && $this->rewardCredits==0)
$this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')');
else
$this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1');
Expand Down Expand Up @@ -575,7 +575,7 @@ abstract class AbstractSmrAccount {
public function setSmrRewardCredits($credits) {
if($this->getSmrRewardCredits()==$credits)
return;
if($this->credits==0&&$this->rewardCredits==0)
if($this->credits==0 && $this->rewardCredits==0)
$this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')');
else
$this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1');
Expand Down Expand Up @@ -1172,7 +1172,7 @@ abstract class AbstractSmrAccount {
$this->setPoints($this->getPoints()-$numPoints,$lastUpdate);
}

public function addPoints($numPoints,SmrAccount &$admin,$reasonID,$suspicion) {
public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) {
//do we have points
$this->setPoints($this->getPoints() + $numPoints,TIME);
$totalPoints = $this->getPoints();
Expand Down Expand Up @@ -1232,7 +1232,7 @@ abstract class AbstractSmrAccount {
$this->hasChanged = true;
}

public function banAccount($expireTime,SmrAccount &$admin,$reasonID,$suspicion,$removeExceptions = false) {
public function banAccount($expireTime,SmrAccount $admin,$reasonID,$suspicion,$removeExceptions = false) {
$this->db->query('REPLACE INTO account_is_closed
(account_id, reason_id, suspicion, expires)
VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($reasonID).', '.$this->db->escapeString($suspicion).', '.$this->db->escapeNumber($expireTime).')');
Expand Down Expand Up @@ -1261,7 +1261,7 @@ abstract class AbstractSmrAccount {
$this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL);
}

public function unbanAccount(SmrAccount &$admin = null,$currException=false) {
public function unbanAccount(SmrAccount $admin = null,$currException=false) {
$adminID = 0;
if($admin!==null)
$adminID = $admin->getAccountID();
Expand Down
36 changes: 18 additions & 18 deletions lib/Default/AbstractSmrCombatWeapon.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ abstract class AbstractSmrCombatWeapon {
return array('MaxDamage' => $this->getMaxDamage(), 'Shield' => $this->getShieldDamage(), 'Armour' => $this->getArmourDamage(), 'Rollover' => $this->isDamageRollover());
}

abstract public function &getModifiedDamageAgainstForces(AbstractSmrPlayer &$weaponPlayer, SmrForce &$forces);
abstract public function &getModifiedDamageAgainstPort(AbstractSmrPlayer &$weaponPlayer, SmrPort &$port);
abstract public function &getModifiedDamageAgainstPlanet(AbstractSmrPlayer &$weaponPlayer, SmrPlanet &$planet);
abstract public function &getModifiedPortDamageAgainstPlayer(SmrPort &$port, AbstractSmrPlayer &$targetPlayer);
abstract public function &getModifiedDamageAgainstPlayer(AbstractSmrPlayer &$weaponPlayer, AbstractSmrPlayer &$targetPlayer);
abstract public function &getModifiedForceDamageAgainstPlayer(SmrForce &$forces, AbstractSmrPlayer &$targetPlayer);

protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer &$weaponPlayer, SmrForce &$forces) {
abstract public function &getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces);
abstract public function &getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port);
abstract public function &getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet);
abstract public function &getModifiedPortDamageAgainstPlayer(SmrPort $port, AbstractSmrPlayer $targetPlayer);
abstract public function &getModifiedDamageAgainstPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer);
abstract public function &getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer);

protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) {
$return['WeaponDamage'] =& $this->getModifiedDamageAgainstForces($weaponPlayer,$forces);
$return['ActualDamage'] =& $forces->doWeaponDamage($return['WeaponDamage']);
if($return['ActualDamage']['KillingShot'])
$return['KillResults'] =& $forces->killForcesByPlayer($weaponPlayer);
return $return;
}

protected function &doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer &$weaponPlayer, AbstractSmrPlayer &$targetPlayer) {
protected function &doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) {
$return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlayer($weaponPlayer,$targetPlayer);
$return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']);

Expand All @@ -97,23 +97,23 @@ abstract class AbstractSmrCombatWeapon {
return $return;
}

protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer &$weaponPlayer, SmrPort &$port) {
protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) {
$return['WeaponDamage'] =& $this->getModifiedDamageAgainstPort($weaponPlayer,$port);
$return['ActualDamage'] =& $port->doWeaponDamage($return['WeaponDamage']);
if($return['ActualDamage']['KillingShot'])
$return['KillResults'] =& $port->killPortByPlayer($weaponPlayer);
return $return;
}

protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer &$weaponPlayer, SmrPlanet &$planet, $delayed) {
protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) {
$return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlanet($weaponPlayer,$planet);
$return['ActualDamage'] =& $planet->doWeaponDamage($return['WeaponDamage'],$delayed);
if($return['ActualDamage']['KillingShot'])
$return['KillResults'] =& $planet->killPlanetByPlayer($weaponPlayer);
return $return;
}

protected function &doPortDamageToPlayer(array &$return, SmrPort &$port, AbstractSmrPlayer &$targetPlayer) {
protected function &doPortDamageToPlayer(array &$return, SmrPort $port, AbstractSmrPlayer $targetPlayer) {
$return['WeaponDamage'] =& $this->getModifiedPortDamageAgainstPlayer($port,$targetPlayer);
$return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']);

Expand All @@ -122,7 +122,7 @@ abstract class AbstractSmrCombatWeapon {
return $return;
}

protected function &doPlanetDamageToPlayer(array &$return, SmrPlanet &$planet, AbstractSmrPlayer &$targetPlayer) {
protected function &doPlanetDamageToPlayer(array &$return, SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) {
$return['WeaponDamage'] =& $this->getModifiedPlanetDamageAgainstPlayer($planet,$targetPlayer);
$return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']);

Expand All @@ -131,7 +131,7 @@ abstract class AbstractSmrCombatWeapon {
return $return;
}

protected function &doForceDamageToPlayer(array &$return, SmrForce &$forces, AbstractSmrPlayer &$targetPlayer) {
protected function &doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer) {
$return['WeaponDamage'] =& $this->getModifiedForceDamageAgainstPlayer($forces,$targetPlayer);
$return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']);

Expand All @@ -140,9 +140,9 @@ abstract class AbstractSmrCombatWeapon {
return $return;
}

abstract public function &shootForces(AbstractSmrPlayer &$weaponPlayer, SmrForce &$forces);
abstract public function &shootPlayer(AbstractSmrPlayer &$weaponPlayer, AbstractSmrPlayer &$targetPlayer);
abstract public function &shootPlayerAsForce(SmrForce &$forces, AbstractSmrPlayer &$targetPlayer);
abstract public function &shootForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces);
abstract public function &shootPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer);
abstract public function &shootPlayerAsForce(SmrForce $forces, AbstractSmrPlayer $targetPlayer);
}

?>
?>
54 changes: 27 additions & 27 deletions lib/Default/AbstractSmrPlayer.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ abstract class AbstractSmrPlayer {
return Globals::getRaceName($this->getRaceID());
}

public static function getColouredRaceNameOrDefault($otherRaceID, AbstractSmrPlayer &$player = null, $linked = false) {
public static function getColouredRaceNameOrDefault($otherRaceID, AbstractSmrPlayer $player = null, $linked = false) {
$relations = 0;
if($player !== null) {
$relations = $player->getRelation($otherRaceID);
Expand Down Expand Up @@ -680,23 +680,23 @@ abstract class AbstractSmrPlayer {
return max(0,min(1, 1 - ($this->getPastMaint() / ($this->getShip()->getSpeed() * 25 + 475))));
}

public function &shootPlayer(AbstractSmrPlayer &$targetPlayer) {
public function &shootPlayer(AbstractSmrPlayer $targetPlayer) {
return $this->getShip()->shootPlayer($targetPlayer);
}

public function &shootForces(SmrForce &$forces) {
public function &shootForces(SmrForce $forces) {
return $this->getShip()->shootForces($forces);
}

public function &shootPort(SmrPort &$port) {
public function &shootPort(SmrPort $port) {
return $this->getShip()->shootPort($port);
}

public function &shootPlanet(SmrPlanet &$planet, $delayed) {
public function &shootPlanet(SmrPlanet $planet, $delayed) {
return $this->getShip()->shootPlanet($planet, $delayed);
}

public function &shootPlayers(array &$targetPlayers) {
public function &shootPlayers(array $targetPlayers) {
return $this->getShip()->shootPlayers($targetPlayers);
}

Expand Down Expand Up @@ -950,10 +950,10 @@ abstract class AbstractSmrPlayer {
}

abstract public function killPlayer($sectorID);
abstract public function &killPlayerByPlayer(AbstractSmrPlayer &$killer);
abstract public function &killPlayerByForces(SmrForce &$forces);
abstract public function &killPlayerByPort(SmrPort &$port);
abstract public function &killPlayerByPlanet(SmrPlanet &$planet);
abstract public function &killPlayerByPlayer(AbstractSmrPlayer $killer);
abstract public function &killPlayerByForces(SmrForce $forces);
abstract public function &killPlayerByPort(SmrPort $port);
abstract public function &killPlayerByPlanet(SmrPlanet $planet);
abstract public function getHome();


Expand Down Expand Up @@ -1300,16 +1300,16 @@ abstract class AbstractSmrPlayer {
}
}

public function canSeeAny(array &$otherPlayerArray) {
foreach($otherPlayerArray as &$otherPlayer) {
public function canSeeAny(array $otherPlayerArray) {
foreach($otherPlayerArray as $otherPlayer) {
if($this->canSee($otherPlayer)) {
return true;
}
}
return false;
}

public function canSee(AbstractSmrPlayer &$otherPlayer) {
public function canSee(AbstractSmrPlayer $otherPlayer) {
if(!$otherPlayer->getShip()->isCloaked())
return true;
if($this->sameAlliance($otherPlayer))
Expand All @@ -1319,51 +1319,51 @@ abstract class AbstractSmrPlayer {
return false;
}

public function equals(AbstractSmrPlayer &$otherPlayer = null) {
return $otherPlayer!==null && $this->getAccountID()==$otherPlayer->getAccountID()&&$this->getGameID()==$otherPlayer->getGameID();
public function equals(AbstractSmrPlayer $otherPlayer = null) {
return $otherPlayer!==null && $this->getAccountID()==$otherPlayer->getAccountID() && $this->getGameID()==$otherPlayer->getGameID();
}

public function sameAlliance(AbstractSmrPlayer &$otherPlayer = null) {
return $otherPlayer != null && ($this->equals($otherPlayer) || ($this->hasAlliance()&&$this->getAllianceID()==$otherPlayer->getAllianceID()));
public function sameAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $otherPlayer != null && ($this->equals($otherPlayer) || ($this->hasAlliance() && $this->getAllianceID()==$otherPlayer->getAllianceID()));
}

public function sharedForceAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function sharedForceAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function forceNAPAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function forceNAPAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function planetNAPAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function planetNAPAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderNAPAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderNAPAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderMAPAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderMAPAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->traderAttackTraderAlliance($otherPlayer) && $this->traderDefendTraderAlliance($otherPlayer);
}

public function traderAttackTraderAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderAttackTraderAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderDefendTraderAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderDefendTraderAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderAttackForceAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderAttackForceAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderAttackPortAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderAttackPortAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

public function traderAttackPlanetAlliance(AbstractSmrPlayer &$otherPlayer = null) {
public function traderAttackPlanetAlliance(AbstractSmrPlayer $otherPlayer = null) {
return $this->sameAlliance($otherPlayer);
}

Expand Down
28 changes: 14 additions & 14 deletions lib/Default/AbstractSmrShip.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class AbstractSmrShip {
return self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID];
}

protected static function &buildBaseShip(Database &$db) {
protected static function &buildBaseShip(Database $db) {
$ship = array();
$ship['Type'] = 'Ship';
$ship['Name'] = $db->getField('ship_name');
Expand Down Expand Up @@ -120,7 +120,7 @@ abstract class AbstractSmrShip {
return self::$CACHE_BASE_SHIPS[$gameTypeID];
}

protected function __construct(AbstractSmrPlayer &$player) {
protected function __construct(AbstractSmrPlayer $player) {
$this->player = $player;
$this->gameID = $player->getGameID();
$this->regenerateBaseShip();
Expand Down Expand Up @@ -191,7 +191,7 @@ abstract class AbstractSmrShip {
public function getPowerUsed() {
$power = 0;
if($this->getNumWeapons()>0)
foreach ($this->weapons as &$weapon)
foreach ($this->weapons as $weapon)
$power += $weapon->getPowerLevel();
return $power;
}
Expand All @@ -212,7 +212,7 @@ abstract class AbstractSmrShip {
return $this->hasCargo(5) || $this->hasCargo(9) || $this->hasCargo(12);
}

public function getDisplayAttackRating(AbstractSmrPlayer &$player) {
public function getDisplayAttackRating(AbstractSmrPlayer $player) {
if($this->hasActiveIllusion())
return $this->getIllusionAttack();
else
Expand Down Expand Up @@ -905,13 +905,13 @@ abstract class AbstractSmrShip {
return $this->getShipTypeID() == 23 || $this->getShipTypeID() == 24 || $this->getShipTypeID() == 25;
}

public function &shootPlayer(AbstractSmrPlayer &$targetPlayer) {
return $this->shootPlayers(array(&$targetPlayer));
public function &shootPlayer(AbstractSmrPlayer $targetPlayer) {
return $this->shootPlayers(array($targetPlayer));
}

public function &shootPlayers(array &$targetPlayers) {
public function &shootPlayers(array $targetPlayers) {
$thisPlayer = $this->getPlayer();
$results = array('Player' => &$thisPlayer, 'TotalDamage' => 0);
$results = array('Player' => $thisPlayer, 'TotalDamage' => 0);
if($thisPlayer->isDead()) {
$results['DeadBeforeShot'] = true;
return $results;
Expand All @@ -933,9 +933,9 @@ abstract class AbstractSmrShip {
return $results;
}

public function &shootForces(SmrForce &$forces) {
public function &shootForces(SmrForce $forces) {
$thisPlayer = $this->getPlayer();
$results = array('Player' => &$thisPlayer, 'TotalDamage' => 0);
$results = array('Player' => $thisPlayer, 'TotalDamage' => 0);
if($thisPlayer->isDead()) {
$results['DeadBeforeShot'] = true;
return $results;
Expand Down Expand Up @@ -972,9 +972,9 @@ abstract class AbstractSmrShip {
return $results;
}

public function &shootPort(SmrPort &$port) {
public function &shootPort(SmrPort $port) {
$thisPlayer = $this->getPlayer();
$results = array('Player' => &$thisPlayer, 'TotalDamage' => 0);
$results = array('Player' => $thisPlayer, 'TotalDamage' => 0);
if($thisPlayer->isDead()) {
$results['DeadBeforeShot'] = true;
return $results;
Expand Down Expand Up @@ -1009,9 +1009,9 @@ abstract class AbstractSmrShip {
return $results;
}

public function &shootPlanet(SmrPlanet &$planet, $delayed) {
public function &shootPlanet(SmrPlanet $planet, $delayed) {
$thisPlayer = $this->getPlayer();
$results = array('Player' => &$thisPlayer, 'TotalDamage' => 0);
$results = array('Player' => $thisPlayer, 'TotalDamage' => 0);
if($thisPlayer->isDead()) {
$results['DeadBeforeShot'] = true;
return $results;
Expand Down
Loading

0 comments on commit 6a860d8

Please sign in to comment.