Completed
Push — work-fleets ( 9e987d...ec9dc8 )
by SuperNova.WS
06:04
created

phalanx.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * phalanx.php
5
 *
6
 * 2.0 copyright (c) 2009-2011 by Gorlum for http://supernova.ws
7
     [!] Full rewrote using SN functions
8
 * 1.2 - Security checks & tests by Gorlum for http://supernova.ws
9
 * @version 1.1
10
 * @original made by ????
11
 * @copyright 2008 by Pada for XNova.project.es
12
 */
13
14
include('common.' . substr(strrchr(__FILE__, '.'), 1));
15
16
lng_include('overview');
17
lng_include('universe');
18
19
$sensorLevel = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX);
20
if (!intval($sensorLevel)) {
21
  message (classLocale::$lang['phalanx_nosensoravailable'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
22
}
23
24
if ($planetrow['planet_type'] != PT_MOON) {
25
  message (classLocale::$lang['phalanx_onlyformoons'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
26
}
27
28
$scan_galaxy  = sys_get_param_int('galaxy');
29
$scan_system  = sys_get_param_int('system');
30
$scan_planet  = sys_get_param_int('planet');
31
$scan_planet_type  = 1; // sys_get_param_int('planettype');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
$id = sys_get_param_id('id');
33
34
$source_galaxy = $planetrow['galaxy'];
35
$source_system = $planetrow['system'];
36
$source_planet = $planetrow['planet'];
37
38
$sensorRange = GetPhalanxRange($sensorLevel);
39
40
$system_distance = abs($source_system - $scan_system);
41
if($system_distance > $sensorRange || $scan_galaxy != $source_galaxy)
42
{
43
  message (classLocale::$lang['phalanx_rangeerror'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
44
}
45
46
$cost = $sensorLevel * 1000;
47
48
if ($planetrow['deuterium'] < $cost)
49
{
50
  message(classLocale::$lang['phalanx_nodeuterium'], "phalanx", '', 3);
51
}
52
53
$planet_scanned = DBStaticPlanet::db_planet_by_gspt($scan_galaxy, $scan_system, $scan_planet, $scan_planet_type);
54
if(!$planet_scanned['id'])
55
{
56
  message(classLocale::$lang['phalanx_planet_not_exists'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
57
}
58
59
if($planet_scanned['destruyed'])
60
{
61
  message (classLocale::$lang['phalanx_planet_destroyed'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
62
}
63
64
DBStaticPlanet::db_planet_update_adjust_by_id(
65
  $user['current_planet'],
66
  array(
67
    'deuterium' => - $cost,
68
  )
69
);
70
71
$template = gettemplate('planet_fleet_list', true);
72
73
$objFleetList = FleetList::dbGetFleetListAndMissileByCoordinates($planet_scanned, true);
74
$fleet_events = flt_parse_objFleetList_to_events($objFleetList, $planet_scanned);
0 ignored issues
show
It seems like $objFleetList defined by \FleetList::dbGetFleetLi...($planet_scanned, true) on line 73 can also be of type array; however, flt_parse_objFleetList_to_events() does only seem to accept object<FleetList>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
75
tpl_assign_fleet($template, $fleet_events);
0 ignored issues
show
It seems like $fleet_events defined by flt_parse_objFleetList_t...tList, $planet_scanned) on line 74 can also be of type null; however, tpl_assign_fleet() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
77
display($template, classLocale::$lang['tech'][STRUC_MOON_PHALANX], false, '', false, false);
78