Skip to content

Commit

Permalink
PHPStan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thekabal committed Apr 10, 2020
1 parent 529685e commit b384394
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions classes/CalcLevels.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
class CalcLevels
{
// This method can be used for armor, holds, shields, torps, beams, and fighters
public static function abstractLevels(int $level, Reg $tkireg): float
public static function abstractLevels(int $level, Reg $tkireg): int
{
$result = round(pow($tkireg->level_factor, $level) * 100);
return $result;
return (int) $result;
}

public static function energy(int $level_power, Reg $tkireg): float
Expand Down
9 changes: 0 additions & 9 deletions classes/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ public function getInsignia(\PDO $pdo_db, string $a_username, array $langvars):
for ($i = 0; $i < 20; $i++)
{
$value = pow(2, $i * 2);
if (!$value)
{
// Pow returned false so we need to return an error.
$player_insignia = "<span style='color:#f00;'>ERR</span> " .
"[<span style='color:#09f; font-size:12px; cursor:help;' " .
"title='Error looking up insignia, please report this error.'>?</span>]";
break;
}

$value *= (500 * 2);
if ($playerinfo['score'] <= $value)
{
Expand Down
4 changes: 2 additions & 2 deletions classes/TraderouteBuildNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static function new(\PDO $pdo_db, string $lang, Reg $tkireg, Smarty $temp
else
{
$counter = 0;
while ($counter < $num_planets)
while ($counter <= $num_planets)
{
echo "<option ";

Expand Down Expand Up @@ -273,7 +273,7 @@ public static function new(\PDO $pdo_db, string $lang, Reg $tkireg, Smarty $temp
else
{
$counter = 0;
while ($counter < $num_planets)
while ($counter <= $num_planets)
{
echo "<option ";

Expand Down
4 changes: 2 additions & 2 deletions classes/TraderouteDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function calc(\PDO $pdo_db, string $type1, string $type2, $start,
$shipspeed = pow($tkireg->level_factor, $playerinfo['engines']);
$triptime = round($distance / $shipspeed);

if (!$triptime && $dest['sector_id'] != $playerinfo['sector'])
if (($triptime > 0) && ($dest['sector_id'] != $playerinfo['sector']))
{
$triptime = 1;
}
Expand All @@ -88,7 +88,7 @@ public static function calc(\PDO $pdo_db, string $type1, string $type2, $start,
$energyscooped = 0;
}

if ($playerinfo['dev_fuelscoop'] == "Y" && !$energyscooped && $triptime == 1)
if (($playerinfo['dev_fuelscoop'] == "Y") && ($energyscooped > 0) && ($triptime == 1))
{
$energyscooped = 100;
}
Expand Down
2 changes: 1 addition & 1 deletion lrscan.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
$result4->MoveNext();
}

if (!$num_detected)
if ($num_detected == 0)
{
echo $langvars['l_none'];
}
Expand Down
2 changes: 1 addition & 1 deletion main.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@
echo "<tr><td style='white-space:nowrap; border:#fff 1px solid; background-color:#500050; text-align:center; padding:0px;'>";
echo "<div class=mnu>";

if (!$num_links)
if ($num_links < 1)
{
echo "&nbsp;<a class=dis>" . $langvars['l_no_warplink'] . "</a>&nbsp;<br>";
}
Expand Down
7 changes: 5 additions & 2 deletions mines.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@
}
else
{
$nummines = preg_replace('/[^0-9]/', '', $nummines);
$numfighters = preg_replace('/[^0-9]/', '', $numfighters);
$nummines = (string) preg_replace('/[^0-9]/', '', (string) $nummines);
$numfighters = (string) preg_replace('/[^0-9]/', '', (string) $numfighters);
$nummines = (int) $nummines;
$numfighters = (int) $numfighters;

if (empty($nummines))
{
$nummines = 0;
Expand Down
18 changes: 12 additions & 6 deletions planet.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,18 @@
elseif ($command == "productions")
{
// Change production percentages
$pore = (int) array_key_exists('pore', $_POST) ? $_POST['pore'] : 0;
$porganics = (int) array_key_exists('porganics', $_POST) ? $_POST['porganics'] : 0;
$pgoods = (int) array_key_exists('pgoods', $_POST) ? $_POST['pgoods'] : 0;
$penergy = (int) array_key_exists('penergy', $_POST) ? $_POST['penergy'] : 0;
$pfighters = (int) array_key_exists('pfighters', $_POST) ? $_POST['pfighters'] : 0;
$ptorp = (int) array_key_exists('ptorp', $_POST) ? $_POST['ptorp'] : 0;
$pore = array_key_exists('pore', $_POST) ? $_POST['pore'] : 0;
$pore = (int) $pore;
$porganics = array_key_exists('porganics', $_POST) ? $_POST['porganics'] : 0;
$porganics = (int) $porganics;
$pgoods = array_key_exists('pgoods', $_POST) ? $_POST['pgoods'] : 0;
$pgoods = (int) $pgoods;
$penergy = array_key_exists('penergy', $_POST) ? $_POST['penergy'] : 0;
$penergy = (int) $penergy;
$pfighters = array_key_exists('pfighters', $_POST) ? $_POST['pfighters'] : 0;
$pfighters = (int) $pfighters;
$ptorp = array_key_exists('ptorp', $_POST) ? $_POST['ptorp'] : 0;
$ptorp = (int) $ptorp;

if ($porganics < 0.0 || $pore < 0.0 || $pgoods < 0.0 || $penergy < 0.0 || $pfighters < 0.0 || $ptorp < 0.0)
{
Expand Down
36 changes: 18 additions & 18 deletions port2.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@
$torp_launchers_upgrade = (int) filter_input(INPUT_POST, 'torp_launchers_upgrade', FILTER_SANITIZE_NUMBER_INT);
$shields_upgrade = (int) filter_input(INPUT_POST, 'shields_upgrade', FILTER_SANITIZE_NUMBER_INT);

$fighter_number = filter_input(INPUT_POST, 'fighter_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$torpedo_number = filter_input(INPUT_POST, 'torpedo_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$armor_number = filter_input(INPUT_POST, 'armor_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$colonist_number = filter_input(INPUT_POST, 'colonist_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_genesis_number = filter_input(INPUT_POST, 'dev_genesis_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_beacon_number = filter_input(INPUT_POST, 'dev_beacon_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_emerwarp_number = filter_input(INPUT_POST, 'dev_emerwarp_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_warpedit_number = filter_input(INPUT_POST, 'dev_warpedit_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_minedeflector_number = filter_input(INPUT_POST, 'dev_minedeflector_number', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
$fighter_number = (int) filter_input(INPUT_POST, 'fighter_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$torpedo_number = (int) filter_input(INPUT_POST, 'torpedo_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$armor_number = (int) filter_input(INPUT_POST, 'armor_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$colonist_number = (int) filter_input(INPUT_POST, 'colonist_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_genesis_number = (int) filter_input(INPUT_POST, 'dev_genesis_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_beacon_number = (int) filter_input(INPUT_POST, 'dev_beacon_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_emerwarp_number = (int) filter_input(INPUT_POST, 'dev_emerwarp_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_warpedit_number = (int) filter_input(INPUT_POST, 'dev_warpedit_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);
$dev_minedeflector_number = (int) filter_input(INPUT_POST, 'dev_minedeflector_number', FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_THOUSAND);

$escapepod_purchase = filter_input(INPUT_POST, 'escapepod_purchase', FILTER_VALIDATE_BOOLEAN);
if ($escapepod_purchase !== true)
Expand Down Expand Up @@ -445,55 +445,55 @@
Tki\Ports::buildOneCol($langvars['l_shields'] . " " . $langvars['l_trade_upgraded'] . " " . $shields_upgrade);
}

if ($fighter_number)
if ($fighter_number > 0)
{
$query = $query . ", ship_fighters = ship_fighters + $fighter_number";
Tki\Ports::buildTwoCol($langvars['l_fighters'] . " " . $langvars['l_trade_added'] . ":", $fighter_number, "left", "right");
}

if ($torpedo_number)
if ($torpedo_number > 0)
{
$query = $query . ", torps=torps + $torpedo_number";
Tki\Ports::buildTwoCol($langvars['l_torps'] . " " . $langvars['l_trade_added'] . ":", $torpedo_number, "left", "right");
}

if ($armor_number)
if ($armor_number > 0)
{
$query = $query . ", armor_pts=armor_pts + $armor_number";
Tki\Ports::buildTwoCol($langvars['l_armorpts'] . " " . $langvars['l_trade_added'] . ":", $armor_number, "left", "right");
}

if ($colonist_number)
if ($colonist_number > 0)
{
$query = $query . ", ship_colonists = ship_colonists + $colonist_number";
Tki\Ports::buildTwoCol($langvars['l_colonists'] . " " . $langvars['l_trade_added'] . ":", $colonist_number, "left", "right");
}

if ($dev_genesis_number)
if ($dev_genesis_number > 0)
{
$query = $query . ", dev_genesis = dev_genesis + $dev_genesis_number";
Tki\Ports::buildTwoCol($langvars['l_genesis'] . " " . $langvars['l_trade_added'] . ":", $dev_genesis_number, "left", "right");
}

if ($dev_beacon_number)
if ($dev_beacon_number > 0)
{
$query = $query . ", dev_beacon = dev_beacon + $dev_beacon_number";
Tki\Ports::buildTwoCol($langvars['l_beacons'] . " " . $langvars['l_trade_added'] . ":", $dev_beacon_number, "left", "right");
}

if ($dev_emerwarp_number)
if ($dev_emerwarp_number > 0)
{
$query = $query . ", dev_emerwarp = dev_emerwarp + $dev_emerwarp_number";
Tki\Ports::buildTwoCol($langvars['l_ewd'] . " " . $langvars['l_trade_added'] . ":", $dev_emerwarp_number, "left", "right");
}

if ($dev_warpedit_number)
if ($dev_warpedit_number > 0)
{
$query = $query . ", dev_warpedit = dev_warpedit + $dev_warpedit_number";
Tki\Ports::buildTwoCol($langvars['l_warpedit'] . " " . $langvars['l_trade_added'] . ":", $dev_warpedit_number, "left", "right");
}

if ($dev_minedeflector_number)
if ($dev_minedeflector_number > 0)
{
$query = $query . ", dev_minedeflector = dev_minedeflector + $dev_minedeflector_number";
Tki\Ports::buildTwoCol($langvars['l_deflect'] . " " . $langvars['l_trade_added'] . ":", $dev_minedeflector_number, "left", "right");
Expand Down
5 changes: 3 additions & 2 deletions sector_fighters.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
echo $langvars['l_sf_attacking'] . "<br>";
$targetfighters = $total_sector_fighters;
$playerbeams = Tki\CalcLevels::abstractLevels($playerinfo['beams'], $tkireg);

if ($calledfrom == 'rsmove.php')
{
$playerinfo['ship_energy'] += $energyscooped;
}

if ($playerbeams > $playerinfo['ship_energy'])
if ($playerbeams > (int) $playerinfo['ship_energy'])
{
$playerbeams = $playerinfo['ship_energy'];
}
Expand All @@ -51,7 +52,7 @@
$playertorpdmg = $tkireg->torp_dmg_rate * $playertorpnum;
$playerarmor = $playerinfo['armor_pts'];
$playerfighters = $playerinfo['ship_fighters'];
if ($targetfighters > 0 && $playerbeams > 0)
if (($targetfighters > 0) && ($playerbeams > 0))
{
if ($playerbeams > round($targetfighters / 2))
{
Expand Down
3 changes: 2 additions & 1 deletion teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
$confirmleave = null;
if (array_key_exists('confirmleave', $_REQUEST) === true)
{
$confirmleave = preg_replace('/[^0-9]/', '', $_REQUEST['confirmleave']);
$confirmleave = (string) preg_replace('/[^0-9]/', '', $_REQUEST['confirmleave']);
$confirmleave = (int) $confirmleave;
}

$invited = null;
Expand Down
2 changes: 1 addition & 1 deletion warpedit2.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
$sectorinfo = $sectors_gateway->selectSectorInfo($target_sector);

if (!$sectorinfo)
if (!is_object($sectorinfo))
{
echo $langvars['l_warp_nosector'] . "<br><br>";
Tki\Text::gotoMain($pdo_db, $lang);
Expand Down
2 changes: 1 addition & 1 deletion warpedit3.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
$sectorinfo = $sectors_gateway->selectSectorInfo($target_sector);

if (!$sectorinfo)
if (!is_object($sectorinfo))
{
echo $langvars['l_warp_nosector'] . "<br><br>";
Tki\Text::gotoMain($pdo_db, $lang);
Expand Down

0 comments on commit b384394

Please sign in to comment.