Completed
Push — work-fleets ( 04acf9...8f8df9 )
by SuperNova.WS
07:02
created

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
 * stat.php
5
 *
6
 * 2.0 copyright (c) 2010-2012 by Gorlum for http://supernova.ws
7
 *   [!] Full rewrote
8
*/
9
10
function stat_tpl_assign(&$template, $selected, $array_name, $array, $sn_group_stat_common) {
11
  global $who;
12
13
  // $sn_group_stat_common = sn_get_groups('STAT_COMMON');
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...
14
  foreach($array as $key => $value) {
15
    if($array_name == 'type' && $who == 2 && !in_array($key, $sn_group_stat_common)) {
16
      continue;
17
    }
18
19
    $header = isset($value['header']) ? $value['header'] : classLocale::$lang['stat_type'][$key];
20
21
    $template->assign_block_vars($array_name, array(
22
      'ID'       => $key,
23
      'HEADER'   => $header,
24
      'SELECTED' => $key == $selected,
25
    ));
26
  }
27
}
28
29
$allow_anonymous = true;
30
31
include('common.' . substr(strrchr(__FILE__, '.'), 1));
32
33
lng_include('stat');
34
35
$sn_group_stat_common = sn_get_groups('STAT_COMMON');
36
$who = sys_get_param_int('who', 1);
37
$type = sys_get_param_int('type');
38
$type = $who != 1 && !in_array($type, $sn_group_stat_common) ? 1 : $type;
39
$range = sys_get_param_int('range', 1);
40
$source = sys_get_param_str('source');
41
42
$template = gettemplate('stat_statistics', true);
43
44
$subject_list = array(
45
  1 => array('header' => classLocale::$lang['stat_player']),
46
);
47
if(!$source) {
48
  $subject_list[2] = array('header' => classLocale::$lang['stat_allys']);
49
}
50
stat_tpl_assign($template, $who, 'subject', $subject_list, $sn_group_stat_common);
51
52
$stat_types = array(
53
   STAT_TOTAL => array(
54
     'type' => 'total',
55
   ),
56
57
   STAT_FLEET => array(
58
     'type' => 'fleet',
59
   ),
60
61
   STAT_TECH => array(
62
     'type' => 'tech',
63
   ),
64
65
   STAT_BUILDING => array(
66
     'type' => 'build',
67
   ),
68
69
   STAT_DEFENSE => array(
70
     'type' => 'defs',
71
   ),
72
73
   STAT_RESOURCE => array(
74
     'type' => 'res',
75
   ),
76
77
   STAT_RAID_TOTAL => array(
78
     'type' => 'raids',
79
   ),
80
81
   STAT_RAID_WON => array(
82
     'type' => 'raidswin',
83
   ),
84
85
   STAT_RAID_LOST => array(
86
     'type' => 'raidsloose',
87
   ),
88
89
  STAT_LVL_BUILDING => array(
90
     'type' => 'lvl_minier',
91
  ),
92
93
  STAT_LVL_TECH => array(
94
     'type' => 'player_rpg_tech_level',
95
  ),
96
97
  STAT_LVL_RAID => array(
98
     'type' => 'lvl_raid',
99
  ),
100
);
101
stat_tpl_assign($template, $type, 'type', $stat_types, $sn_group_stat_common);
102
103
$Rank = $stat_types[$type]['type'];
104
105
$is_common_stat = in_array($type, $sn_group_stat_common);
106
$start = floor($range / 100 % 100) * 100;
107
$query = db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source);
108
109
// TODO - Не работает, если игроков на Блице > 100
110
$record_count = $source ? classSupernova::$db->db_num_rows($query) : ($who == 1 ? DBStaticUser::db_user_count() : DBStaticAlly::db_ally_count());
111
// pdump($record_count, '$record_count');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
112
// $record_count = db_num_rows($query);
113
114
$page_count = floor($record_count / 100);
115
$pages = array();
116
for($i = 0; $i <= $page_count; $i++) {
117
  $first_element = $i * 100 + 1;
118
  $last_element = $first_element + 99;
119
  $pages[$first_element] = array(
120
    'header' => "{$first_element}-{$last_element}",
121
  );
122
}
123
124
$range = $range > $record_count ? $record_count : $range;
125
stat_tpl_assign($template, $range, 'range', $pages, $sn_group_stat_common);
126
127
while ($row = db_fetch($query)) {
128
  $row_stat = array(
129
    'ID' => $row['id'],
130
    'RANK'        => $row['rank'],
131
    'RANK_CHANGE' => $row['rank_old'] ? $row['rank_old'] - $row['rank'] : 0,
132
    'POINTS' => pretty_number($row['points']),
133
  );
134
//pdump($row);
135
136
  if($who == 1) {
137
    $row_stat['ALLY_NAME'] = $row['ally_name'];
138
    $row_stat['ALLY_ID'] = $row['ally_id'];
139
    empty($row['username']) ? $row['username'] = $row['name'] : false;
140
    $row_stat['NAME'] = player_nick_render_to_html($row, array('icons' => empty($source), 'color' => empty($source)));
0 ignored issues
show
array('icons' => empty($...lor' => empty($source)) is of type array<string,boolean,{"i...an","color":"boolean"}>, 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...
141
//    $row_stat['NAME'] = player_nick_render_to_html(array(
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...
142
//      'id' => $row['id'],
143
//      // TODO - Добавлять реальное имя игрока на Блице для закрытого раунда
144
//      'username' => $row['name'],
145
//      'gender' => isset($row['gender']) ? $row['gender'] : GENDER_UNKNOWN,
146
//      // 'gender',
147
//      // 'race',
148
//      // 'ally_tag',
149
//    ), array('icons' => empty($source), 'color' => empty($source)));
150
  } else {
151
    $row_stat['MEMBERS'] = $row['ally_members'];
152
    $row_stat['POINTS_PER_MEMBER'] = pretty_number(floor($row['points'] / $row['ally_members']));
153
    $row_stat['NAME'] = $row['name'];
154
  }
155
156
  $template->assign_block_vars('stat', $row_stat);
157
}
158
159
$next_run = sys_schedule_get_prev_run(classSupernova::$config->stats_schedule, classSupernova::$config->var_stat_update, true);
160
$template->assign_vars(array(
161
  'REFRESH_DATE' => classSupernova::$config->var_stat_update ? date(FMT_DATE_TIME, strtotime(classSupernova::$config->var_stat_update) + SN_CLIENT_TIME_DIFF) : '',
162
  'NEXT_DATE' => $next_run ? date(FMT_DATE_TIME, $next_run + SN_CLIENT_TIME_DIFF) : '',
163
  'RANGE' => $range,
164
  'SUBJECT' => $who,
165
  'TYPE' => $type,
166
  'USER_ALLY' => $user['ally_id'],
167
  // TODO - Для блица - вытаскивать blitz_player_id и подсвечивать пользователя на блице
168
  'USER_ID' => $source ? 0 : $user['id'],
169
  'SOURCE' => $source,
170
  'STATS_HIDE_PM_LINK' => classSupernova::$config->stats_hide_pm_link || $source,
171
));
172
173
display($template, classLocale::$lang['stat_header'], !empty($user), '', false, !empty($user));
174