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 | * buddy.php |
||
5 | * Friend system |
||
6 | * |
||
7 | * v3.0 Fully rewrote by Gorlum for http://supernova.ws |
||
8 | * [!] Full rewrote from scratch |
||
9 | * |
||
10 | * Idea from buddy.php Created by Perberos. All rights reversed (C) 2006 |
||
11 | * */ |
||
12 | use Buddy\Buddy; |
||
13 | use Buddy\BuddyException; |
||
14 | |||
15 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||
16 | |||
17 | class_exists('Buddy\Buddy'); |
||
18 | |||
19 | |||
20 | /** |
||
21 | * @var array $user |
||
22 | */ |
||
23 | global $user; |
||
24 | |||
25 | lng_include('buddy'); |
||
26 | |||
27 | $result = array(); |
||
28 | sn_db_transaction_start(); |
||
29 | try { |
||
30 | $cBuddy = new \Buddy\BuddyRoutingParams(array( |
||
31 | 'gc' => classSupernova::$gc, |
||
32 | 'buddy_id' => sys_get_param_id('buddy_id'), |
||
33 | 'mode' => sys_get_param_str('mode'), |
||
34 | 'new_friend_id_safe' => sys_get_param_id('request_user_id'), |
||
35 | 'new_friend_name_unsafe' => sys_get_param_str_unsafe('request_user_name'), |
||
36 | 'new_request_text' => sys_get_param_str('request_text'), |
||
37 | 'user' => $user, |
||
38 | )); |
||
39 | |||
40 | // $className = classSupernova::$gc->buddyClass; |
||
0 ignored issues
–
show
|
|||
41 | // $className->route($cBuddy); |
||
42 | // $className = classSupernova::$gc->buddyClass; |
||
43 | classSupernova::$gc->buddy->route($cBuddy); |
||
44 | |||
45 | // $buddy_id = sys_get_param_id('buddy_id'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
49% 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. ![]() |
|||
46 | // if ($buddy_id) { |
||
47 | // /** |
||
48 | // * @var Buddy\Buddy\BuddyModel $buddy |
||
49 | // */ |
||
50 | // $buddy = classSupernova::$gc->dbRowOperator->getById(classSupernova::$gc->buddy, $buddy_id); |
||
51 | // |
||
52 | // if ($buddy->isEmpty()) { |
||
53 | // throw new Exception('buddy_err_not_exist', ERR_ERROR); |
||
54 | // } |
||
55 | // |
||
56 | // $mode = sys_get_param_str('mode'); |
||
57 | // switch ($mode) { |
||
58 | // case 'accept': |
||
59 | // $buddy->accept($user); |
||
60 | // break; |
||
61 | // case 'delete': |
||
62 | // $buddy->decline($user); |
||
63 | // break; |
||
64 | // } |
||
65 | // } else { |
||
66 | // // New request? |
||
67 | // // Checking for user ID - in case if it was request from outside buddy system |
||
68 | // $new_friend_id_safe = sys_get_param_id('request_user_id'); |
||
69 | // $new_friend_name = sys_get_param_str_unsafe('request_user_name'); |
||
70 | // if ($new_friend_id_safe || $new_friend_name) { |
||
71 | // $buddy = classSupernova::$gc->buddy; |
||
72 | // $new_request_text = sys_get_param_str('request_text'); |
||
73 | // $buddy->beFriend($user, $new_friend_id_safe, $new_friend_name, $new_request_text); |
||
74 | // } |
||
75 | // } |
||
76 | } catch (BuddyException $e) { |
||
77 | $result[] = array( |
||
78 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
||
79 | 'MESSAGE' => classLocale::$lang[$e->getMessage()], |
||
80 | ); |
||
81 | $e->getCode() == ERR_NONE ? sn_db_transaction_commit() : sn_db_transaction_rollback(); |
||
82 | } |
||
83 | sn_db_transaction_rollback(); |
||
84 | unset($buddy); |
||
85 | |||
86 | // TODO - Это просто заглушка. Дойдут руки - разобраться, в чём проблема |
||
87 | sn_db_transaction_rollback(); |
||
88 | |||
89 | empty($template_result) ? $template_result = array() : false; |
||
90 | |||
91 | foreach (Buddy::db_buddy_list_by_user(classSupernova::$gc->db, $user['id']) as $row) { |
||
0 ignored issues
–
show
It seems like
\classSupernova::$gc->db can also be of type object<Closure> ; however, Buddy\Buddy::db_buddy_list_by_user() does only seem to accept object<db_mysql> , 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. ![]() |
|||
92 | $row['BUDDY_REQUEST'] = sys_bbcodeParse($row['BUDDY_REQUEST']); |
||
93 | |||
94 | $row['BUDDY_ACTIVE'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_ACTIVE; |
||
95 | $row['BUDDY_DENIED'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_DENIED; |
||
96 | $row['BUDDY_INCOMING'] = $row['BUDDY_OWNER_ID'] == $user['id']; |
||
97 | $row['BUDDY_ONLINE'] = floor((SN_TIME_NOW - $row['onlinetime']) / 60); |
||
98 | |||
99 | $template_result['.']['buddy'][] = $row; |
||
100 | } |
||
101 | |||
102 | $template_result += array( |
||
103 | 'PAGE_HEADER' => classLocale::$lang['buddy_buddies'], |
||
104 | 'PAGE_HINT' => classLocale::$lang['buddy_hint'], |
||
105 | 'USER_ID' => $user['id'], |
||
106 | 'REQUEST_USER_ID' => isset($new_friend_row['id']) ? $new_friend_row['id'] : 0, |
||
107 | 'REQUEST_USER_NAME' => isset($new_friend_row['username']) ? $new_friend_row['username'] : '', |
||
108 | ); |
||
109 | |||
110 | $template_result['.']['result'] = is_array($template_result['.']['result']) ? $template_result['.']['result'] : array(); |
||
111 | $template_result['.']['result'] += $result; |
||
112 | |||
113 | $template = gettemplate('buddy', true); |
||
114 | $template->assign_recursive($template_result); |
||
115 | |||
116 | display($template); |
||
117 |
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.