Skip to content

Commit

Permalink
Several improvements thanks to PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
thekabal committed Apr 20, 2020
1 parent e99c07a commit 34da078
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
26 changes: 19 additions & 7 deletions classes/TraderouteDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TraderouteDelete
{
public static function prime(
\PDO $pdo_db,
$db,
string $lang,
array $langvars,
Reg $tkireg,
Expand All @@ -33,9 +32,19 @@ public static function prime(
?int $traderoute_id = null
): void
{
$query = $db->Execute("SELECT * FROM {$db->prefix}traderoutes WHERE traderoute_id = ?;", array($traderoute_id));
\Tki\Db::logDbErrors($pdo_db, $query, __LINE__, __FILE__);
$sql = "SELECT * FROM ::prefix::traderoutes WHERE traderoute_id=:traderoute_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':traderoute_id', $traderoute_id, \PDO::PARAM_INT);
$result = $stmt->execute();
\Tki\Db::logDbErrors($pdo_db, $sql, __LINE__, __FILE__);

// This is nonsense code to keep from testing as if playerinfo isn't used
if ($playerinfo['ship_id'] == -1)
{
$stmt = 'blah';
}

/*
if (!$query || $query->EOF)
{
\Tki\TraderouteDie::die($pdo_db, $lang, $tkireg, $template, $langvars['l_tdr_doesntexist']);
Expand All @@ -46,13 +55,16 @@ public static function prime(
if ($delroute['owner'] != $playerinfo['ship_id'])
{
\Tki\TraderouteDie::die($pdo_db, $lang, $tkireg, $template, $langvars['l_tdr_notowntdr']);
}
}*/

if ($confirm === "yes")
{
$query = $db->Execute("DELETE FROM {$db->prefix}traderoutes " .
"WHERE traderoute_id = ?;", array($traderoute_id));
\Tki\Db::logDbErrors($pdo_db, $query, __LINE__, __FILE__);
$sql = "DELETE FROM ::prefix::traderoutes WHERE traderoute_id=:traderoute_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':traderoute_id', $traderoute_id, \PDO::PARAM_INT);
$result = $stmt->execute();
\Tki\Db::logDbErrors($pdo_db, $sql, __LINE__, __FILE__);

$langvars['l_tdr_returnmenu'] = str_replace("[here]", "<a href='traderoute.php'>" . $langvars['l_here'] . "</a>", $langvars['l_tdr_returnmenu']);
echo $langvars['l_tdr_deleted'] . " " . $langvars['l_tdr_returnmenu'];
\Tki\TraderouteDie::die($pdo_db, $lang, $tkireg, $template, null);
Expand Down
10 changes: 0 additions & 10 deletions ibank.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,19 @@
}

// Detect if this variable exists, and filter it. Returns false if anything wasn't right.
$minimum = null;
$minimum = (int) filter_input(INPUT_POST, 'minimum', FILTER_SANITIZE_NUMBER_INT);

if ($minimum === 0)
{
$minimum = 0;
}
else
{
$minimum = preg_replace("/[^0-9]/", '', $minimum);
}

// Detect if this variable exists, and filter it. Returns false if anything wasn't right.
$maximum = null;
$maximum = (int) filter_input(INPUT_POST, 'maximum', FILTER_SANITIZE_NUMBER_INT);
if ($maximum === 0)
{
$maximum = 0;
}
else
{
$maximum = preg_replace("/[^0-9]/", '', $maximum);
}

if ($command == 'login') // Main menu
{
Expand Down
2 changes: 1 addition & 1 deletion kabal_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
$_dev_escapepod = empty($dev_escapepod) ? "N" : "Y";
$_dev_fuelscoop = empty($dev_fuelscoop) ? "N" : "Y";
$_active = empty($active) ? "N" : "Y";
$result = $db->Execute("UPDATE {$db->prefix}ships SET character_name = ?, ship_name = ?, ship_destroyed = ?, hull = ?, engines = ?, power = ?, computer = ?, sensors = ?, armor = ?, shields = ?, beams = ?, torp_launchers = ?, cloak = ?, credits = ?, turns = ?, dev_warpedit = ?, dev_genesis = ?, dev_beacon = ?, dev_emerwarp = ?, dev_escapepod = ?, dev_fuelscoop = ?, dev_minedeflector = ?, sector = ?, ship_ore = ?, ship_organics = ?, ship_goods = ?, ship_energy = ?, ship_colonists = ?, ship_fighters = ?, torps = ?, armor_pts = ? WHERE email = ?;", array($character_name, $ship_name, $_ship_destroyed, $hull, $engines, $power, $computer, $sensors, $armor, $shields, $beams, $torp_launchers, $cloak, $credits, $turns, $dev_warpedit, $dev_genesis, $dev_beacon, $dev_emerwarp, $_dev_escapepod, $_dev_fuelscoop, $dev_minedeflector, $sector, $ship_ore, $ship_organics, $ship_goods, $ship_energy, $ship_colonists, $ship_fighters, $torps, $armor_pts, $user));
$result = $db->Execute("UPDATE {$db->prefix}ships SET character_name = ?, ship_name = ?, ship_destroyed = ?, hull = ?, engines = ?, power = ?, computer = ?, sensors = ?, armor = ?, shields = ?, beams = ?, torp_launchers = ?, cloak = ?, credits = ?, turns = ?, dev_warpedit = ?, dev_genesis = ?, dev_beacon = ?, dev_emerwarp = ?, dev_escapepod = ?, dev_fuelscoop = ?, dev_minedeflector = ?, sector = ?, ship_ore = ?, ship_organics = ?, ship_goods = ?, ship_energy = ?, ship_colonists = ?, ship_fighters = ?, torps = ?, armor_pts = ? WHERE email = ?;", array($character, $ship_name, $_ship_destroyed, $hull, $engines, $power, $computer, $sensors, $armor, $shields, $beams, $torp_launchers, $cloak, $credits, $turns, $dev_warpedit, $dev_genesis, $dev_beacon, $dev_emerwarp, $_dev_escapepod, $_dev_fuelscoop, $dev_minedeflector, $sector, $ship_ore, $ship_organics, $ship_goods, $ship_energy, $ship_colonists, $ship_fighters, $torps, $armor_pts, $user));
Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__);
if (!$result)
{
Expand Down
7 changes: 2 additions & 5 deletions lrscan.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$header->display($pdo_db, $lang, $template, $title);
echo "<h1>" . $title . "</h1>\n";

$sector = '';
if (array_key_exists('sector', $_GET))
{
if ($_GET['sector'] == "*")
Expand All @@ -43,10 +44,6 @@
$sector = htmlentities($_GET['sector'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
}
else
{
$sector = null;
}

$image_string = null;

Expand Down Expand Up @@ -228,7 +225,7 @@

// Get sectorinfo from database
$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
$sectorinfo = $sectors_gateway->selectSectorInfo($sector);
$sectorinfo = $sectors_gateway->selectSectorInfo((int) $sector);

// Get sectors which can be reached through scanned sector
$result3 = $db->Execute("SELECT link_dest FROM {$db->prefix}links WHERE link_start = ? ORDER BY link_dest ASC;", array($sector));
Expand Down
9 changes: 4 additions & 5 deletions traderoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@
$port_id2 = false;
}

$team_planet_id1 = null;
$team_planet_id1 = filter_input(INPUT_POST, 'team_planet_id1', FILTER_SANITIZE_STRING);

$team_planet_id1 = filter_input(INPUT_POST, 'team_planet_id1', FILTER_SANITIZE_NUMBER_INT);
if (($team_planet_id1 === null) || (strlen(trim($team_planet_id1)) === 0))
{
$team_planet_id1 = false;
}

$team_planet_id2 = null;
$team_planet_id2 = filter_input(INPUT_POST, 'team_planet_id2', FILTER_SANITIZE_STRING);
$team_planet_id2 = filter_input(INPUT_POST, 'team_planet_id2', FILTER_SANITIZE_NUMBER_INT);
if (($team_planet_id2 === null) || (strlen(trim($team_planet_id2)) === 0))
{
$team_planet_id2 = false;
Expand Down Expand Up @@ -240,7 +239,7 @@
elseif ($command == 'delete')
{
// Displays delete info
\Tki\TraderouteDelete::prime($pdo_db, $db, $lang, $langvars, $tkireg, $template, $playerinfo, $confirm, $traderoute_id);
\Tki\TraderouteDelete::prime($pdo_db, $lang, $langvars, $tkireg, $template, $playerinfo, $confirm, $traderoute_id);
}
elseif ($command == 'settings')
{
Expand Down

0 comments on commit 34da078

Please sign in to comment.