Completed
Push — work-fleets ( 88e4e3...4e1f0c )
by SuperNova.WS
12:49
created

overview.php (18 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
 * index.php - overview.php
4
 *
5
 * 2.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
6
 *     [-] Removed News frame
7
 *     [-] Time & Usersonline moved to Top-Frame
8
 * 2.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
9
 *     [*] Complying with PCG
10
 * 2.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
11
 *     [+] Redo flying fleet list
12
 * 2.1 - copyright (c) 2010 by Gorlum for http://supernova.ws
13
 *     [+] Planets on planet list now have indication of planet fill
14
 *     [+] Planets on planet list now have indication when there is enemy fleet flying to planet
15
 * 2.0 - copyright (c) 2010 by Gorlum for http://supernova.ws
16
 *     [+] Now there is full planet list on right side of screen a-la oGame
17
 *     [+] Planet list now include icons for buildings/tech/fleet on progress
18
 * 1.5 - copyright (c) 2010 by Gorlum for http://supernova.ws
19
 *     [*] Subplanet timers now use sn_timer.js library
20
 * 1.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
21
 *     [*] All mainplanet timers now use new sn_timer.js library
22
 * 1.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
23
 *     [*] Adjusted layouts of player infos
24
 * 1.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
25
 *     [*] Adjusted layouts of planet infos
26
 * 1.1 - Security checks by Gorlum for http://supernova.ws
27
 * @version 1
28
 * @copyright 2008 By Chlorel for XNova
29
 */
30
31
//define('SN_RENDER_NAVBAR_PLANET', false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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
33
use DBStatic\DBStaticPlanet;
34
use DBStatic\DBStaticUser;
35
36
include('common.' . substr(strrchr(__FILE__, '.'), 1));
37
38
//$ccc = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
39
//foreach(DBStatic\DBStaticUser::db_user_list_non_bots() as $ip) {
40
//  $ccc++;
41
//}
42
//pdump($ccc);
43
//
44
//foreach(DBStatic\DBStaticUser::db_user_list_non_bots() as $ip) {
45
//  pdump($ip['id']);
46
//  $ccc++;
47
//}
48
//
49
//pdump(DBStatic\DBStaticUser::db_user_list_non_bots());
50
51
lng_include('overview');
52
53
$result = array();
54
55
switch($mode = sys_get_param_str('mode')) {
56
  case 'manage':
57
    sn_sys_sector_buy('overview.php?mode=manage');
58
59
    $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
60
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
61
62
    $template  = gettemplate('planet_manage', true);
63
    $planet_id = sys_get_param_id('planet_id');
64
65
    if(sys_get_param_str('rename') && ($new_name_unsafe = sys_get_param_str_unsafe('new_name'))) {
66
      $planetrow['name'] = $new_name_unsafe;
67
      DBStaticPlanet::db_planet_update_set_by_id(
68
        $planetrow['id'],
69
        array(
70
          'name' => $new_name_unsafe,
71
        )
72
      );
73
    } elseif(sys_get_param_str('action') == 'make_capital') {
74
      try {
75
        sn_db_transaction_start();
76
        $user = DBStaticUser::db_user_by_id($user['id'], true, '*');
77
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
78
79 View Code Duplication
        if($planetrow['planet_type'] != PT_PLANET) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
          throw new exception(classLocale::$lang['ov_capital_err_not_a_planet'], ERR_ERROR);
81
        }
82
83
        if($planetrow['id'] == $user['id_planet']) {
84
          throw new exception(classLocale::$lang['ov_capital_err_capital_already'], ERR_ERROR);
85
        }
86
87
        if($user_dark_matter < classSupernova::$config->planet_capital_cost) {
0 ignored issues
show
The property planet_capital_cost does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
88
          throw new exception(classLocale::$lang['ov_capital_err_no_dark_matter'], ERR_ERROR);
89
        }
90
91
        rpg_points_change($user['id'], RPG_CAPITAL, -classSupernova::$config->planet_capital_cost,
0 ignored issues
show
The property planet_capital_cost does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
92
          array('Planet %s ID %d at coordinates %s now become Empire Capital', $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow))
0 ignored issues
show
array('Planet %s ID %d a...oordinates($planetrow)) is of type array<integer,?,{"0":"st...":"?","2":"?","3":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
        );
94
95
        DBStaticUser::db_user_set_by_id(
96
          $user['id'],
97
          array(
98
            'id_planet' => $planetrow['id'],
99
            'galaxy'    => $planetrow['galaxy'],
100
            'system'    => $planetrow['system'],
101
            'planet'    => $planetrow['planet'],
102
          )
103
        );
104
105
        $user['id_planet'] = $planetrow['id'];
106
        $result[] = array(
107
          'STATUS'  => ERR_NONE,
108
          'MESSAGE' => classLocale::$lang['ov_capital_err_none'],
109
        );
110
        sn_db_transaction_commit();
111
        sys_redirect('overview.php?mode=manage');
112
      } catch(exception $e) {
113
        sn_db_transaction_rollback();
114
        $result[] = array(
115
          'STATUS'  => $e->getCode(),
116
          'MESSAGE' => $e->getMessage(),
117
        );
118
      }
119
    } elseif(sys_get_param_str('action') == 'planet_teleport') {
120
      try {
121
        if(!uni_coordinates_valid($new_coordinates = array(
122
          'galaxy' => sys_get_param_int('new_galaxy'),
123
          'system' => sys_get_param_int('new_system'),
124
          'planet' => sys_get_param_int('new_planet')))
125
        ) {
126
          throw new exception(classLocale::$lang['ov_teleport_err_wrong_coordinates'], ERR_ERROR);
127
        }
128
129
        sn_db_transaction_start();
130
        // При телепорте обновлять данные не надо - просто получить текущие данные и залочить их
131
        $user = DBStaticUser::db_user_by_id($user['id'], true, '*');
132
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
133
//        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
134
//        $user = $global_data['user'];
135
//        $planetrow = $global_data['planet'];
136
137
        $can_teleport = uni_planet_teleport_check($user, $planetrow, $new_coordinates);
138
        if($can_teleport['result'] != ERR_NONE) {
139
          throw new exception($can_teleport['message'], $can_teleport['result']);
140
        }
141
142
        rpg_points_change($user['id'], RPG_TELEPORT, -classSupernova::$config->planet_teleport_cost,
143
          array(&classLocale::$lang['ov_teleport_log_record'], $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), uni_render_coordinates($new_coordinates))
0 ignored issues
show
array(&\classLocale::$la...ates($new_coordinates)) is of type array<integer,?,{"0":"?"...":"?","3":"?","4":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
144
        );
145
        $planet_teleport_next = SN_TIME_NOW + classSupernova::$config->planet_teleport_timeout;
146
        DBStaticPlanet::db_planet_update_by_gspt(
147
          $planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], PT_ALL,
148
          array(
149
            'galaxy'               => $new_coordinates['galaxy'],
150
            'system'               => $new_coordinates['system'],
151
            'planet'               => $new_coordinates['planet'],
152
            'planet_teleport_next' => $planet_teleport_next,
153
          ),
154
          array()
155
        );
156
157
        if($planetrow['id'] == $user['id_planet']) {
158
          DBStaticUser::db_user_set_by_id(
159
            $user['id'],
160
            array(
161
              'galaxy' => $new_coordinates['galaxy'],
162
              'system' => $new_coordinates['system'],
163
              'planet' => $new_coordinates['planet'],
164
            )
165
          );
166
        }
167
168
        // $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
169
        sn_db_transaction_commit();
170
        $user = DBStaticUser::db_user_by_id($user['id'], true, '*');
171
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
172
        $result[] = array(
173
          'STATUS'  => ERR_NONE,
174
          'MESSAGE' => classLocale::$lang['ov_teleport_err_none'],
175
        );
176
        sys_redirect('overview.php?mode=manage');
177
      } catch(exception $e) {
178
        sn_db_transaction_rollback();
179
        $result[] = array(
180
          'STATUS'  => $e->getCode(),
181
          'MESSAGE' => $e->getMessage(),
182
        );
183
      }
184
    } elseif(sys_get_param_str('action') == 'planet_abandon') {
185
      // if(sec_password_check($user['id'], sys_get_param('abandon_confirm'))) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
186
      if(classSupernova::$auth->password_check(sys_get_param('abandon_confirm'))) {
187
        if($user['id_planet'] != $user['current_planet'] && $user['current_planet'] == $planet_id) {
188
          $destroyed = SN_TIME_NOW + 60 * 60 * 24;
189
          DBStaticPlanet::db_planet_update_set_by_id(
190
            $user['current_planet'],
191
            array(
192
              'destruyed' => $destroyed,
193
              'id_owner'  => 0,
194
            )
195
          );
196
197
          DBStaticPlanet::db_planet_set_by_parent(
198
            $user['current_planet'],
199
            array(
200
              'destruyed' => $destroyed,
201
              'id_owner'  => 0,
202
            )
203
          );
204
          DBStaticUser::db_user_set_by_id(
205
            $user['id'],
206
            array('current_planet' => $user['id_planet'])
207
          );
208
          message(classLocale::$lang['ov_delete_ok'], classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
209
        } else {
210
          message(classLocale::$lang['ov_delete_wrong_planet'], classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
211
        }
212
      } else {
213
        message(classLocale::$lang['ov_delete_wrong_pass'] , classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
214
      }
215
    } elseif(
216
      ($hire = sys_get_param_int('hire')) && in_array($hire, sn_get_groups('governors'))
217
      && (
218
        !get_unit_param($hire, P_MAX_STACK) ||
219
        ($planetrow['PLANET_GOVERNOR_ID'] != $hire) ||
220
        (
221
          $planetrow['PLANET_GOVERNOR_ID'] == $hire &&
222
          $planetrow['PLANET_GOVERNOR_LEVEL'] < get_unit_param($hire, P_MAX_STACK)
223
        )
224
      )
225
    ) {
226
      sn_db_transaction_start();
227
      $user = DBStaticUser::db_user_by_id($user['id'], true);
228
      $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true);
229
      $build_data = eco_get_build_data($user, $planetrow, $hire, $planetrow['PLANET_GOVERNOR_ID'] == $hire ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0);
230
      if($build_data['CAN'][BUILD_CREATE]) {
231
        if($planetrow['PLANET_GOVERNOR_ID'] == $hire) {
232
          $planetrow['PLANET_GOVERNOR_LEVEL']++;
233
        } else {
234
          $planetrow['PLANET_GOVERNOR_LEVEL'] = 1;
235
          $planetrow['PLANET_GOVERNOR_ID'] = $hire;
236
        }
237
        DBStaticPlanet::db_planet_update_set_by_id(
238
          $planetrow['id'],
239
          array(
240
            'PLANET_GOVERNOR_ID' => $hire,
241
            // TODO - change it
242
            'PLANET_GOVERNOR_LEVEL' => $planetrow['PLANET_GOVERNOR_LEVEL'],
243
          )
244
        );
245
246
        rpg_points_change(
247
          $user['id'],
248
          RPG_GOVERNOR,
249
          -$build_data[BUILD_CREATE][RES_DARK_MATTER],
250
          sprintf(classLocale::$lang['ov_governor_purchase'], classLocale::$lang['tech'][$hire], $hire, $planetrow['PLANET_GOVERNOR_LEVEL'], uni_render_planet_full($planetrow, '', false, true))
251
        );
252
253
        //  => 'Игрок купил Губернатора %1$s ID %2$d уровня %3$d на планету %4$s',
254
        // die();
255
      }
256
      sn_db_transaction_commit();
257
      sys_redirect('overview.php?mode=manage');
258
      die();
259
    }
260
261
    lng_include('mrc_mercenary');
262
    int_planet_pretemplate($planetrow, $template);
263
    foreach(sn_get_groups('governors') as $governor_id) {
264
      if($planetrow['planet_type'] == PT_MOON && $governor_id == MRC_TECHNOLOGIST) {
265
        continue;
266
      }
267
268
      $governor_level = $planetrow['PLANET_GOVERNOR_ID'] == $governor_id ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0;
269
      $build_data = eco_get_build_data($user, $planetrow, $governor_id, $governor_level);
270
      $template->assign_block_vars('governors', array(
271
        'ID'         => $governor_id,
272
        'NAME'       => classLocale::$lang['tech'][$governor_id],
273
        'COST'       => $build_data[BUILD_CREATE][RES_DARK_MATTER],
274
        'MAX'        => get_unit_param($governor_id, P_MAX_STACK),
275
        'LEVEL'      => $governor_level,
276
        'LEVEL_PLUS' => mrc_get_level($user, $planetrow, $governor_id) - $governor_level,
277
      ));
278
    }
279
280
    $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
281
    $planet_density_index = $planetrow['density_index'];
282
    $density_price_chart = planet_density_price_chart($planetrow);
283
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
284
285
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
286
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
287
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
288
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
289
    $can_teleport = uni_planet_teleport_check($user, $planetrow);
290
    $template->assign_vars(array(
291
      'DARK_MATTER'           => $user_dark_matter,
292
293
      'PLANET_FILL'           => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
294
      'PLANET_FILL_BAR'       => $planet_fill,
295
      'SECTOR_CAN_BUY'        => $sector_cost <= $user_dark_matter,
296
      'SECTOR_COST'           => $sector_cost,
297
      'SECTOR_COST_TEXT'      => pretty_number($sector_cost),
298
      'planet_field_current'  => $planetrow['field_current'],
299
      'planet_field_max'      => eco_planet_fields_max($planetrow),
300
301
      'CAN_TELEPORT'          => $can_teleport['result'] == ERR_NONE,
302
      'CAN_NOT_TELEPORT_MSG'  => $can_teleport['message'],
303
      'TELEPORT_COST_TEXT'    => pretty_number(classSupernova::$config->planet_teleport_cost, true, $user_dark_matter),
304
305
      'CAN_CAPITAL'           => $user_dark_matter >= classSupernova::$config->planet_capital_cost,
0 ignored issues
show
The property planet_capital_cost does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
306
      'CAPITAL_COST_TEXT'     => pretty_number(classSupernova::$config->planet_capital_cost, true, $user_dark_matter),
0 ignored issues
show
The property planet_capital_cost does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
307
308
      'PLANET_DENSITY_INDEX'  => $planet_density_index,
309
      'PLANET_CORE_TEXT'      => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
310
311
      'IS_CAPITAL'            => $planetrow['id'] == $user['id_planet'],
312
313
      'PAGE_HINT'   => classLocale::$lang['ov_manage_page_hint'],
314
    ));
315
316
    foreach($result as &$a_result) {
317
      $template->assign_block_vars('result', $a_result);
318
    }
319
320
    display($template, classLocale::$lang['rename_and_abandon_planet']);
321
  break;
322
323
  default:
324
    sn_sys_sector_buy();
325
326
    if(sys_get_param_str('rename') && $new_name_unsafe = sys_get_param_str_unsafe('new_name')) {
327
      $planetrow['name'] = $new_name_unsafe;
328
      DBStaticPlanet::db_planet_update_set_by_id(
329
        $planetrow['id'],
330
        array(
331
          'name' => $new_name_unsafe,
332
        )
333
      );
334
335
    }
336
337
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
338
339
    $template = gettemplate('planet_overview', true);
340
341
    $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
342
343
    $planet_density_index = $planetrow['density_index'];
344
    $density_price_chart = planet_density_price_chart($planetrow);
345
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
346
347
    rpg_level_up($user, RPG_STRUCTURE);
348
    rpg_level_up($user, RPG_RAID);
349
    rpg_level_up($user, RPG_TECH);
350
    rpg_level_up($user, RPG_EXPLORE);
351
352
    $fleet_id = 1;
353
354
//    $fleet_and_missiles_list = FleetList::fleet_and_missiles_list_incoming($user['id']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
355
//    $fleets = flt_parse_fleets_to_events($fleet_and_missiles_list);
356
    $fleet_and_missiles_list = FleetList::dbGetFleetListAndMissileINCOMING($user['id']);
357
    $fleets = flt_parse_objFleetList_to_events($fleet_and_missiles_list);
358
359
    $planet_count = 0;
360
    $planets_query = DBStaticPlanet::db_planet_list_sorted($user, false, '*');
361
    foreach($planets_query as $an_id => $UserPlanet) {
362
      sn_db_transaction_start();
363
      $UserPlanet = sys_o_get_updated($user, $UserPlanet['id'], SN_TIME_NOW, false, true);
364
      sn_db_transaction_commit();
365
      $list_planet_que = $UserPlanet['que'];
366
      $UserPlanet = $UserPlanet['planet'];
367
368
      $template_planet = tpl_parse_planet($UserPlanet);
369
370
      $planet_fleet_id = 0;
371
      $fleet_list = $template_planet['fleet_list'];
372 View Code Duplication
      if($fleet_list['own']['count']) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
373
        $planet_fleet_id = "p{$UserPlanet['id']}";
374
        $fleets_to_planet[$UserPlanet['id']] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id);
375
//        $fleet_id++;tpl_parse_fleet_sn
376
      }
377
      if($UserPlanet['planet_type'] == PT_MOON) {
378
        continue;
379
      }
380
      $moon = DBStaticPlanet::db_planet_by_parent($UserPlanet['id']);
381
      if($moon) {
382
        $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100));
383
      } else {
384
        $moon_fill = 0;
385
      }
386
387
//      $moon_fleets = flt_get_fleets_to_planet($moon);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
388
      $moon_fleets = FleetList::EMULATE_flt_get_fleets_to_planet($moon);
389
//      $moon_fleets = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
390
//      $fleet_db_list = FleetList::dbGetFleetListAndMissileByCoordinates($moon);
391
//      /**
392
//       * @var Fleet[] $array_of_Fleet
393
//       */
394
//      $array_of_Fleet = array();
395
//      if(!empty($fleet_db_list) && $fleet_db_list->count()) {
396
//        foreach($fleet_db_list->_container as $fleet_id => $objFleet) {
397
//          $array_of_Fleet[$fleet_id] = $objFleet;
398
//        }
399
//        $moon_fleets = flt_get_fleets_to_planet_by_array_of_Fleet($array_of_Fleet);
400
//      }
401
402
      $template->assign_block_vars('planet', array_merge($template_planet, array(
403
        'PLANET_FLEET_ID'  => $planet_fleet_id,
404
405
        'MOON_ID'      => $moon['id'],
406
        'MOON_NAME'    => $moon['name'],
407
        'MOON_IMG'     => $moon['image'],
408
        'MOON_FILL'    => min(100, $moon_fill),
409
        'MOON_ENEMY'   => !empty($moon_fleets['enemy']['count']) ? $moon_fleets['enemy']['count'] : 0,
410
411
        'MOON_PLANET'  => $moon['parent_planet'],
412
      )));
413
414
      $planet_count++;
415
    }
416
417
    tpl_assign_fleet($template, $fleets_to_planet);
418
    tpl_assign_fleet($template, $fleets);
0 ignored issues
show
It seems like $fleets defined by flt_parse_objFleetList_t...leet_and_missiles_list) on line 357 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...
419
420
    $lune = $planetrow['planet_type'] == PT_PLANET ? DBStaticPlanet::db_planet_by_parent($planetrow['id']) : DBStaticPlanet::db_planet_by_id($planetrow['parent_planet']);
421
    if($lune) {
422
      $template->assign_vars(array(
423
        'MOON_ID' => $lune['id'],
424
        'MOON_IMG' => $lune['image'],
425
        'MOON_NAME' => $lune['name'],
426
      ));
427
    }
428
429
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
430
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
431
432
    $planet_recyclers_orbiting = 0;
433
    foreach(Fleet::$snGroupRecyclers as $recycler_id) {
434
      $planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id);
435
    }
436
437
    int_planet_pretemplate($planetrow, $template);
438
439
    $sn_group_ques = sn_get_groups('ques');
440
    if(!defined('GAME_STRUCTURES_DISABLED') || !GAME_STRUCTURES_DISABLED) {
441
      foreach(array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) {
442
        $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']];
443
        $template->assign_block_vars('ques', array(
444
          'ID'     => $que_id,
445
          'NAME'   => classLocale::$lang['sys_ques'][$que_id],
446
          'LENGTH' => empty($this_que) ? 0 : count($this_que),
447
        ));
448
449
        if(!empty($this_que)) {
450
          foreach($this_que as $que_item) {
451
            $template->assign_block_vars('que', que_tpl_parse_element($que_item));
452
          }
453
        }
454
      }
455
    }
456
457
    $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_FLEET);
458
    $template->assign_block_vars('ques', array(
459
      'ID'     => QUE_HANGAR,
460
      'NAME'   => classLocale::$lang['sys_ques'][QUE_HANGAR],
461
      'LENGTH' => $que_hangar_length,
462
    ));
463
464
    if(!defined('GAME_DEFENSE_DISABLED') || !GAME_DEFENSE_DISABLED) {
465
      $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_DEFENSE);
466
      $template->assign_block_vars('ques', array(
467
        'ID'     => SUBQUE_DEFENSE,
468
        'NAME'   => classLocale::$lang['sys_ques'][SUBQUE_DEFENSE],
469
        'LENGTH' => $que_hangar_length,
470
      ));
471
    }
472
473
    $overview_planet_rows = $user['opt_int_overview_planet_rows'];
474
    $overview_planet_columns = $user['opt_int_overview_planet_columns'];
475
476
    if($overview_planet_rows <= 0 && $overview_planet_columns <= 0) {
477
      $overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows'];
478
      $overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns'];
479
    }
480
481
    if($overview_planet_rows > 0 && $overview_planet_columns <= 0) {
482
      $overview_planet_columns = ceil($planet_count / $overview_planet_rows);
483
    }
484
485
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
486
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
487
    $governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0;
488
    $template->assign_vars(array(
489
      'USER_ID'               => $user['id'],
490
      'user_username'         => $user['username'],
491
      'USER_AUTHLEVEL'        => $user['authlevel'],
492
493
      'NEW_MESSAGES'          => $user['new_message'],
494
      'NEW_LEVEL_MINER'       => $level_miner,
495
      'NEW_LEVEL_RAID'        => $level_raid,
496
497
      'planet_diameter'       => pretty_number($planetrow['diameter']),
498
      'planet_field_current'  => $planetrow['field_current'],
499
      'planet_field_max'      => eco_planet_fields_max($planetrow),
500
      'PLANET_FILL'           => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
501
      'PLANET_FILL_BAR'       => $planet_fill,
502
      'metal_debris'          => pretty_number($planetrow['debris_metal']),
503
      'crystal_debris'        => pretty_number($planetrow['debris_crystal']),
504
      'PLANET_RECYCLERS'      => $planet_recyclers_orbiting,
505
      'planet_image'          => $planetrow['image'],
506
      'planet_temp_min'       => $planetrow['temp_min'],
507
      'planet_temp_avg'       => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2),
508
      'planet_temp_max'       => $planetrow['temp_max'],
509
      'planet_density'        => $planetrow['density'],
510
      'planet_density_index'  => $planetrow['density_index'],
511
      'planet_density_text'   => classLocale::$lang['uni_planet_density_types'][$planetrow['density_index']],
512
513
      'GATE_LEVEL'            => mrc_get_level($user, $planetrow, STRUC_MOON_GATE),
514
      'GATE_JUMP_REST_TIME'   => uni_get_time_to_jump($planetrow),
515
516
      'ADMIN_EMAIL'           => classSupernova::$config->game_adminEmail,
517
518
      'PLANET_GOVERNOR_ID'    => $planetrow['PLANET_GOVERNOR_ID'],
519
//      'PLANET_GOVERNOR_LEVEL' => $planetrow['PLANET_GOVERNOR_LEVEL'] mrc_get_level($user, $planetrow,),
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
520
      'PLANET_GOVERNOR_LEVEL' => $governor_level,
521
      'PLANET_GOVERNOR_LEVEL_PLUS' => mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level,
522
      'PLANET_GOVERNOR_NAME'  => classLocale::$lang['tech'][$planetrow['PLANET_GOVERNOR_ID']],
523
524
      'LIST_ROW_COUNT'        => $overview_planet_rows,
525
      'LIST_COLUMN_COUNT'     => $overview_planet_columns,
526
527
      'DARK_MATTER'           => $user_dark_matter,
528
529
      'PLANET_DENSITY_INDEX'  => $planet_density_index,
530
      'PLANET_CORE_TEXT'      => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
531
532
      'SECTOR_CAN_BUY'        => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER),
533
      'SECTOR_COST'           => $sector_cost,
534
      'SECTOR_COST_TEXT'      => pretty_number($sector_cost),
535
    ));
536
    tpl_set_resource_info($template, $planetrow, $fleets_to_planet, 2);
537
538
    foreach($result as &$a_result) {
539
      $template->assign_block_vars('result', $a_result);
540
    }
541
542
    $classLocale = classLocale::$lang;
543
    display($template, "{$classLocale['ov_overview']} - {$classLocale['sys_planet_type'][$planetrow['planet_type']]} {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]");
544
  break;
545
}
546