Test Failed
Branch trunk (d809b8)
by SuperNova.WS
05:48
created

tpl_helpers.php ➔ templateFillPercent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
// Compare function to sort fleet in time order
4
function tpl_assign_fleet_compare($a, $b)
5
{
6
  if($a['fleet']['OV_THIS_PLANET'] == $b['fleet']['OV_THIS_PLANET'])
7
  {
8
    if($a['fleet']['OV_LEFT'] == $b['fleet']['OV_LEFT'])
9
    {
10
      return 0;
11
    }
12
    return ($a['fleet']['OV_LEFT'] < $b['fleet']['OV_LEFT']) ? -1 : 1;
13
  }
14
  else
15
  {
16
    return $a['fleet']['OV_THIS_PLANET'] ? -1 : 1;
17
  }
18
}
19
20
function tpl_assign_fleet(&$template, $fleets, $js_name = 'fleets')
21
{
22
  if(!$fleets)
23
  {
24
    return;
25
  }
26
27
  usort($fleets, 'tpl_assign_fleet_compare');
28
29
  foreach($fleets as $fleet_data)
30
  {
31
    $template->assign_block_vars($js_name, $fleet_data['fleet']);
32
33
    if($fleet_data['ships'])
34
    {
35
      foreach($fleet_data['ships'] as $ship_data)
36
      {
37
        $template->assign_block_vars("{$js_name}.ships", $ship_data);
38
      }
39
    }
40
  }
41
}
42
43
// function that parses internal fleet representation (as array(id => count))
44
function tpl_parse_fleet_sn($fleet, $fleet_id)
45
{
46
  global $lang, $user;
47
48
  $user_data = &$user;
49
50
  $return['fleet'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$return was never initialized. Although not strictly required by PHP, it is generally a good practice to add $return = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
51
    'ID'                 => $fleet_id,
52
53
    'METAL'              => $fleet[RES_METAL],
54
    'CRYSTAL'            => $fleet[RES_CRYSTAL],
55
    'DEUTERIUM'          => $fleet[RES_DEUTERIUM],
56
  );
57
58
  foreach ($fleet as $ship_id => $ship_amount)
59
  {
60
    if(in_array($ship_id, sn_get_groups('fleet')))
61
    {
62
      $single_ship_data = get_ship_data($ship_id, $user_data);
63
      $return['ships'][$ship_id] = array(
64
        'ID'          => $ship_id,
65
        'NAME'        => $lang['tech'][$ship_id],
66
        'AMOUNT'      => $ship_amount,
67
        'CONSUMPTION' => $single_ship_data['consumption'],
68
        'SPEED'       => $single_ship_data['speed'],
69
        'CAPACITY'    => $single_ship_data['capacity'],
70
      );
71
    }
72
  }
73
74
  return $return;
75
}
76
77
/**
78
 * @param array      $fleet
79
 * @param int        $index
80
 * @param array|bool $user_data
81
 *
82
 * @return mixed
83
 */
84
function tpl_parse_fleet_db($fleet, $index, $user_data = false){return sn_function_call('tpl_parse_fleet_db', array($fleet, $index, $user_data, &$result));}
0 ignored issues
show
Bug introduced by
The variable $result does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
85
/**
86
 * @param array      $fleet
87
 * @param int        $index
88
 * @param array|bool $user_data
89
 * @param            $result
90
 *
91
 * @return mixed
92
 */
93
function sn_tpl_parse_fleet_db($fleet, $index, $user_data = false, &$result) {
94
  global $lang, $user;
95
96
  if(!$user_data) {
97
    $user_data = $user;
98
  }
99
100
  if($fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] == MT_AKS) {
101
    $aks = doquery("SELECT * FROM {{aks}} WHERE id={$fleet['fleet_group']} LIMIT 1;", true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, 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...
102
  }
103
104
  $spy_level = $user['id'] == $fleet['fleet_owner'] ? 100 : GetSpyLevel($user);
105
106
  $result['fleet'] = isset($result['fleet']) ? $result['fleet'] : array();
107
108
  $result['fleet'] = array(
109
    'NUMBER'             => $index,
110
111
    'ID'                 => $fleet['fleet_id'],
112
    'OWNER'              => $fleet['fleet_owner'],
113
    'TARGET_OWNER'       => $fleet['fleet_target_owner'],
114
115
    'MESSAGE'            => $fleet['fleet_mess'],
116
    'MISSION'            => $fleet['fleet_mission'],
117
    'MISSION_NAME'       => $lang['type_mission'][$fleet['fleet_mission']],
118
    'ACS'                => $aks['name'],
0 ignored issues
show
Bug introduced by
The variable $aks does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
119
    'AMOUNT'             => $spy_level >= 4 ? (pretty_number($fleet['fleet_amount']) . ($fleet['fleet_resource_metal'] + $fleet['fleet_resource_crystal'] + $fleet['fleet_resource_deuterium'] ? '+' : '')) : '?',
120
121
    'METAL'              => $spy_level >= 8 ? $fleet['fleet_resource_metal'] : 0,
122
    'CRYSTAL'            => $spy_level >= 8 ? $fleet['fleet_resource_crystal'] : 0,
123
    'DEUTERIUM'          => $spy_level >= 8 ? $fleet['fleet_resource_deuterium'] : 0,
124
125
    'START_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$fleet['fleet_start_type']],
126
    'START_COORDS'       => "[{$fleet['fleet_start_galaxy']}:{$fleet['fleet_start_system']}:{$fleet['fleet_start_planet']}]",
127
    'START_TIME_TEXT'    => date(FMT_DATE_TIME, $fleet['fleet_end_time'] + SN_CLIENT_TIME_DIFF),
128
    'START_LEFT'         => floor($fleet['fleet_end_time'] + 1 - SN_TIME_NOW),
129
    'START_URL'          => uni_render_coordinates_href($fleet, 'fleet_start_', 3),
130
    'START_NAME'         => $fleet['fleet_start_name'],
131
132
    'END_TYPE_TEXT_SH'   => $lang['sys_planet_type_sh'][$fleet['fleet_end_type']],
133
    'END_COORDS'         => "[{$fleet['fleet_end_galaxy']}:{$fleet['fleet_end_system']}:{$fleet['fleet_end_planet']}]",
134
    'END_TIME_TEXT'      => date(FMT_DATE_TIME, $fleet['fleet_start_time'] + SN_CLIENT_TIME_DIFF),
135
    'END_LEFT'           => floor($fleet['fleet_start_time'] + 1 - SN_TIME_NOW),
136
    'END_URL'            => uni_render_coordinates_href($fleet, 'fleet_end_', 3),
137
    'END_NAME'           => $fleet['fleet_end_name'],
138
139
    'STAY_TIME'          => date(FMT_DATE_TIME, $fleet['fleet_end_stay'] + SN_CLIENT_TIME_DIFF),
140
    'STAY_LEFT'          => floor($fleet['fleet_end_stay'] + 1 - SN_TIME_NOW),
141
142
    'OV_LABEL'           => $fleet['ov_label'],
143
    'EVENT_TIME_TEXT'    => date(FMT_DATE_TIME, $fleet['event_time'] + SN_CLIENT_TIME_DIFF),
144
    'OV_LEFT'            => floor($fleet['event_time'] + 1 - SN_TIME_NOW),
145
    'OV_THIS_PLANET'     => $fleet['ov_this_planet'],
146
  );
147
148
  $ship_list = explode(';', $fleet['fleet_array']);
149
150
  $ship_id = 0;
151
  if($spy_level >= 6) {
152
    foreach($ship_list as $ship_record) {
153
      if($ship_record) {
154
        $ship_data = explode(',', $ship_record);
155
        if($spy_level >= 10) {
156
          $single_ship_data = get_ship_data($ship_data[0], $user_data);
157
          $result['ships'][$ship_data[0]] = array(
158
            'ID'          => $ship_data[0],
159
            'NAME'        => $lang['tech'][$ship_data[0]],
160
            'AMOUNT'      => $ship_data[1],
161
            'AMOUNT_TEXT' => pretty_number($ship_data[1]),
162
            'CONSUMPTION' => $single_ship_data['consumption'],
163
            'SPEED'       => $single_ship_data['speed'],
164
            'CAPACITY'    => $single_ship_data['capacity'],
165
          );
166
        } else {
167
          $result['ships'][$ship_data[0]] = array(
168
            'ID'          => $ship_id++,
169
            'NAME'        => $lang['tech'][UNIT_SHIPS],
170
            'AMOUNT'      => $ship_data[1],
171
            'AMOUNT_TEXT' => pretty_number($ship_data[1]),
172
            'CONSUMPTION' => 0,
173
            'CONSUMPTION_TEXT' => '0',
174
            'SPEED'       => 0,
175
            'CAPACITY'    => 0,
176
          );
177
        }
178
      }
179
    }
180
  }
181
182
  return $result;
183
}
184
185
function tpl_parse_planet_que($que, $planet, $que_id)
186
{
187
  $hangar_que = array();
188
  $que_hangar = $que['ques'][$que_id][$planet['id_owner']][$planet['id']];
189
  if(!empty($que_hangar))
190
  {
191
    foreach($que_hangar as $que_item)
192
    {
193
      $hangar_que['que'][] = array('id' => $que_item['que_unit_id'], 'count' => $que_item['que_unit_amount']);
194
      $hangar_que[$que_item['que_unit_id']] += $que_item['que_unit_amount'];
195
    }
196
  }
197
198
  return $hangar_que;
199
}
200
201
function tpl_parse_planet($planet, &$fleets)
202
{
203
  global $lang;
204
205
  $que = que_get($planet['id_owner'], $planet['id'], false);
206
  $structure_que = tpl_parse_planet_que($que, $planet, QUE_STRUCTURES); // TODO Заменить на que_tpl_parse_element($que_element);
207
  $structure_que_first = is_array($structure_que['que']) ? reset($structure_que['que']) : array();
208
  $hangar_que = tpl_parse_planet_que($que, $planet, SUBQUE_FLEET); // TODO Заменить на que_tpl_parse_element($que_element);
209
  $hangar_que_first = is_array($hangar_que['que']) ? reset($hangar_que['que']) : array();
210
  $defense_que = tpl_parse_planet_que($que, $planet, SUBQUE_DEFENSE); // TODO Заменить на que_tpl_parse_element($que_element);
211
  $defense_que_first = is_array($defense_que['que']) ? reset($defense_que['que']) : array();
212
213
  $result = array(
214
    'ID'            => $planet['id'],
215
    'NAME'          => $planet['name'],
216
    'IMAGE'         => $planet['image'],
217
218
    'GALAXY'        => $planet['galaxy'],
219
    'SYSTEM'        => $planet['system'],
220
    'PLANET'        => $planet['planet'],
221
    'TYPE'          => $planet['planet_type'],
222
    'COORDINATES'   => uni_render_coordinates($planet),
223
224
    'METAL_PERCENT'     => $planet['metal_mine_porcent'] * 10,
225
    'CRYSTAL_PERCENT'   => $planet['crystal_mine_porcent'] * 10,
226
    'DEUTERIUM_PERCENT' => $planet['deuterium_sintetizer_porcent'] * 10,
227
228
    'STRUCTURE' => isset($structure_que_first['id']) ? $lang['tech'][$structure_que_first['id']] : '',
229
230
    // 'HANGAR'        => isset($hangar_que['que'][0]['id']) ? $lang['tech'][$hangar_que['que'][0]['id']] : '',
231
    'HANGAR'        => isset($hangar_que_first['id']) ? $lang['tech'][$hangar_que_first['id']] : '',
232
    'hangar_que'    => $hangar_que,
233
234
    // 'DEFENSE'        => isset($defense_que['que'][0]['id']) ? $lang['tech'][$defense_que['que'][0]['id']] : '',
235
    'DEFENSE'        => isset($defense_que_first['id']) ? $lang['tech'][$defense_que_first['id']] : '',
236
    'defense_que'    => $defense_que,
237
238
    'FIELDS_CUR'    => $planet['field_current'],
239
    'FIELDS_MAX'    => eco_planet_fields_max($planet),
240
    'FILL'          => min(100, floor($planet['field_current'] / eco_planet_fields_max($planet) * 100)),
241
242
    'fleet_list'      => $fleet_list = flt_get_fleets_to_planet($planet),
243
    'FLEET_OWN'       => $fleet_list['own']['count'],
244
    'FLEET_ENEMY'     => $fleet_list['enemy']['count'],
245
    'FLEET_NEUTRAL'   => $fleet_list['neutral']['count'],
246
    'PLANET_FLEET_ID' => !empty($fleet_list['own']['count']) ? getUniqueFleetId($planet) : 0,
247
248
    'PLANET_GOVERNOR_ID' => $planet['PLANET_GOVERNOR_ID'],
249
    'PLANET_GOVERNOR_NAME' => $lang['tech'][$planet['PLANET_GOVERNOR_ID']],
250
    'PLANET_GOVERNOR_LEVEL' => $planet['PLANET_GOVERNOR_LEVEL'],
251
    'PLANET_GOVERNOR_LEVEL_MAX' => get_unit_param($planet['PLANET_GOVERNOR_ID'], P_MAX_STACK),
252
  );
253
254
  if (!empty($fleet_list['own']['count'])) {
255
    $fleets[$planet['id']] = tpl_parse_fleet_sn($fleet_list['own']['total'], $result['PLANET_FLEET_ID']);
256
  }
257
258
  if(!empty($que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']]))
259
  {
260
    $result['building_que'] = array();
261
    $building_que = &$que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']];
262
    foreach($building_que as $que_element)
263
    {
264
      $result['building_que'][] = que_tpl_parse_element($que_element);
265
    }
266
  }
267
268
  return $result;
269
}
270
271
function flt_get_fleets_to_planet($planet, $fleet_db_list = 0)
272
{
273
  if(!($planet && $planet['id']) && !$fleet_db_list)
274
  {
275
    return $planet;
276
  }
277
278
  global $user;
279
280
  if($fleet_db_list === 0)
281
  {
282
    $fleet_db_list = fleet_and_missiles_list_by_coordinates($planet);
283
  }
284
285
  foreach($fleet_db_list as $fleet)
0 ignored issues
show
Bug introduced by
The expression $fleet_db_list of type array|integer is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
286
  {
287
    if($fleet['fleet_owner'] == $user['id'])
288
    {
289
      if($fleet['fleet_mission'] == MT_MISSILE)
290
      {
291
        continue;
292
      }
293
      $fleet_ownage = 'own';
294
    }
295
    else
296
    {
297
      switch($fleet['fleet_mission'])
298
      {
299
        case MT_ATTACK:
300
        case MT_AKS:
301
        case MT_DESTROY:
302
        case MT_MISSILE:
303
          $fleet_ownage = 'enemy';
304
        break;
305
306
        default:
307
          $fleet_ownage = 'neutral';
308
        break;
309
310
      }
311
    }
312
313
    $fleet_list[$fleet_ownage]['fleets'][$fleet['fleet_id']] = $fleet;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fleet_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fleet_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
314
315
    if($fleet['fleet_mess'] == 1 || ($fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] == MT_RELOCATE) || ($fleet['fleet_target_owner'] != $user['id']))
316
    {
317
//      $fleet_sn = flt_expand($fleet);
318
      $fleet_sn = sys_unit_str2arr($fleet['fleet_array']);
319
      foreach($fleet_sn as $ship_id => $ship_amount)
320
      {
321
        if(in_array($ship_id, sn_get_groups('fleet')))
322
        {
323
          $fleet_list[$fleet_ownage]['total'][$ship_id] += $ship_amount;
324
        }
325
      }
326
    }
327
328
    $fleet_list[$fleet_ownage]['count']++;
0 ignored issues
show
Bug introduced by
The variable $fleet_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
329
    $fleet_list[$fleet_ownage]['amount'] += $fleet['fleet_amount'];
330
    $fleet_list[$fleet_ownage]['total'][RES_METAL] += $fleet['fleet_resource_metal'];
331
    $fleet_list[$fleet_ownage]['total'][RES_CRYSTAL] += $fleet['fleet_resource_crystal'];
332
    $fleet_list[$fleet_ownage]['total'][RES_DEUTERIUM] += $fleet['fleet_resource_deuterium'];
333
  }
334
335
  return $fleet_list;
336
}
337
338
/**
339
 * @param template $template
340
 * @param array    $planetrow
341
 * @param array    $fleets_to_planet
342
 * @param int      $round
343
 */
344
function tpl_set_resource_info(&$template, $planetrow, $fleets_to_planet = array(), $round = 0)
345
{
346
  $template->assign_vars(array(
347
    'RESOURCE_ROUNDING' => $round,
348
349
    'PLANET_ENERGY' => $planetrow['energy_used'],
350
    'ENERGY_BALANCE_NUMBER' => $planetrow['energy_max'] - $planetrow['energy_used'],
351
    'ENERGY_BALANCE' => pretty_number($planetrow['energy_max'] - $planetrow['energy_used'], true, true),
352
    'ENERGY_MAX_NUMBER' => $planetrow['energy_max'],
353
    'ENERGY_MAX_NUMBER_TEXT_NO_COLOR' => pretty_number($planetrow['energy_max']),
354
    'ENERGY_MAX_NUMBER_TEXT' => Tools::numberPercentSpan($planetrow['energy_max'], $planetrow['energy_used']),
355
    'ENERGY_MAX' => pretty_number($planetrow['energy_max'], true, -$planetrow['energy_used']),
0 ignored issues
show
Documentation introduced by
-$planetrow['energy_used'] is of type integer|double, but the function expects a boolean.

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...
356
    'ENERGY_FILL' => round(($planetrow["energy_used"]/($planetrow["energy_max"]+1))*100,0),
357
358
    'PLANET_METAL' => round($planetrow["metal"], $round),
359
    'PLANET_METAL_TEXT' => pretty_number($planetrow["metal"], $round, $planetrow["metal_max"]),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
360
    'PLANET_METAL_MAX' => round($planetrow["metal_max"], $round),
361
    'PLANET_METAL_MAX_TEXT' => Tools::numberPercentSpan($planetrow["metal_max"], $planetrow["metal"]),
362
    'PLANET_METAL_MAX_NO_COLOR' => pretty_number($planetrow["metal_max"]),
363
    'PLANET_METAL_FILL' => round(($planetrow["metal"]/($planetrow["metal_max"]+1))*100,0),
364
    'PLANET_METAL_PERHOUR' => round($planetrow["metal_perhour"], 5),
365
    'PLANET_METAL_FLEET_TEXT' => pretty_number($fleets_to_planet[$planetrow['id']]['fleet']['METAL'], $round, true),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
366
367
    'PLANET_CRYSTAL' => round($planetrow["crystal"], $round),
368
    'PLANET_CRYSTAL_TEXT' => pretty_number($planetrow["crystal"], $round, $planetrow["crystal_max"]),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
369
    'PLANET_CRYSTAL_MAX' => round($planetrow["crystal_max"], $round),
370
    'PLANET_CRYSTAL_MAX_TEXT' => Tools::numberPercentSpan($planetrow["crystal_max"], $planetrow["crystal"]),
371
    'PLANET_CRYSTAL_MAX_NO_COLOR' => pretty_number($planetrow["crystal_max"]),
372
    'PLANET_CRYSTAL_FILL' => round(($planetrow["crystal"]/($planetrow["crystal_max"]+1))*100,0),
373
    'PLANET_CRYSTAL_PERHOUR' => round($planetrow["crystal_perhour"], 5),
374
    'PLANET_CRYSTAL_FLEET_TEXT' => pretty_number($fleets_to_planet[$planetrow['id']]['fleet']['CRYSTAL'], $round, true),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
375
376
    'PLANET_DEUTERIUM' => round($planetrow["deuterium"], $round),
377
    'PLANET_DEUTERIUM_TEXT' => pretty_number($planetrow["deuterium"], $round, $planetrow["deuterium_max"]),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
378
    'PLANET_DEUTERIUM_MAX' => round($planetrow["deuterium_max"], $round),
379
    'PLANET_DEUTERIUM_MAX_TEXT' => Tools::numberPercentSpan($planetrow["deuterium_max"], $planetrow["deuterium"]),
380
    'PLANET_DEUTERIUM_MAX_NO_COLOR' => pretty_number($planetrow["deuterium_max"]),
381
    'PLANET_DEUTERIUM_FILL' => round(($planetrow["deuterium"]/($planetrow["deuterium_max"]+1))*100,0),
382
    'PLANET_DEUTERIUM_PERHOUR' => round($planetrow["deuterium_perhour"], 5),
383
    'PLANET_DEUTERIUM_FLEET_TEXT' => pretty_number($fleets_to_planet[$planetrow['id']]['fleet']['DEUTERIUM'], $round, true),
0 ignored issues
show
Documentation introduced by
$round is of type integer, but the function expects a boolean.

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...
384
  ));
385
}
386
387
/**
388
 * @param template $template
389
 */
390
function templateFillPercent($template) {
391
  for ($i = 100; $i >= 0; $i -= 10) {
392
    $template->assign_block_vars('percent', array('PERCENT' => $i));
393
  }
394
}
395