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