Completed
Push — work-fleets ( 17041b...4aef09 )
by SuperNova.WS
05:32
created

DBStaticChat::db_chat_message_get_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 10
rs 9.4285
1
<?php
2
3
class DBStaticChat {
4
5
  // Chat *************************************************************************************************************
6
  public static function db_chat_player_list_online($chat_refresh_rate, $ally_add) {
7
    $sql_date = SN_TIME_NOW - $chat_refresh_rate * 2;
8
9
    return doquery(
10
      "SELECT u.*, cp.*
11
    FROM {{chat_player}} AS cp
12
      JOIN {{users}} AS u ON u.id = cp.chat_player_player_id
13
    WHERE
14
      `chat_player_refresh_last` >= '{$sql_date}'
15
      AND (`banaday` IS NULL OR `banaday` <= " . SN_TIME_NOW . ")
16
      {$ally_add}
17
    ORDER BY authlevel DESC, `username`");
18
  }
19
20
  /**
21
   * @param $user_id
22
   * @param $nick
23
   * @param $ally_id
24
   * @param $message
25
   * @param $chat_message_sender_name
26
   * @param $chat_message_recipient_id
27
   * @param $chat_message_recipient_name
28
   */
29
  public static function db_chat_message_insert($user_id, $nick, $ally_id, $message, $chat_message_sender_name = '', $chat_message_recipient_id = 0, $chat_message_recipient_name = '') {
30
    doquery(
31
      "INSERT INTO
32
          {{chat}}
33
        SET
34
          `chat_message_sender_id` = {$user_id},
35
          `user` = '{$nick}',
36
          `ally_id` = '{$ally_id}',
37
          `message` = '{$message}',
38
          `timestamp` = " . SN_TIME_NOW . ",
39
          `chat_message_sender_name` = '{$chat_message_sender_name}',
40
          `chat_message_recipient_id` = {$chat_message_recipient_id},
41
          `chat_message_recipient_name` = '{$chat_message_recipient_name}'"
42
    );
43
  }
44
45
  /**
46
   * @param $alliance
47
   *
48
   * @return array|bool|mysqli_result|null
49
   */
50
  public static function db_chat_message_count_by_ally($alliance) {
51
    $rows = doquery("SELECT count(1) AS CNT FROM {{chat}} WHERE ally_id = '{$alliance}';", 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...
52
53
    return $rows;
54
  }
55
56
  /**
57
   * @param $alliance
58
   * @param $where_add
59
   * @param $start_row
60
   * @param $page_limit
61
   *
62
   * @return array|bool|mysqli_result|null
63
   */
64
  public static function db_chat_message_get_page($alliance, $where_add, $start_row, $page_limit) {
65
    $query = doquery(
66
      "SELECT c.*, u.authlevel
67
      FROM
68
        {{chat}} AS c
69
        LEFT JOIN {{users}} AS u ON u.id = c.chat_message_sender_id
70
      WHERE c.chat_message_recipient_id IS NULL AND c.ally_id = '{$alliance}' {$where_add} ORDER BY messageid DESC LIMIT {$start_row}, {$page_limit};");
71
72
    return $query;
73
  }
74
75
  /**
76
   * @param $chat_directive
77
   * @param $user
78
   */
79
  public static function db_chat_player_update_invisibility($chat_directive, $user) {
80
    doquery("UPDATE {{chat_player}} SET `chat_player_invisible` = {$chat_directive} WHERE `chat_player_player_id` = {$user['id']} LIMIT 1");
81
  }
82
83
  /**
84
   * @param $temp
85
   * @param $chat_player_subject
86
   */
87
  public static function db_chat_player_update_unmute($temp, $chat_player_subject) {
88
    doquery("UPDATE {{chat_player}} SET `chat_player_muted` = 0, `chat_player_mute_reason` = '{$temp}' WHERE `chat_player_player_id` = {$chat_player_subject['id']} LIMIT 1");
89
  }
90
91
  /**
92
   * @param $date_compiled
93
   * @param $chat_command_parsed_two
94
   * @param $chat_player_subject
95
   */
96
  public static function db_chat_player_update_mute($date_compiled, $chat_command_parsed_two, $chat_player_subject) {
97
    doquery("UPDATE {{chat_player}} SET `chat_player_muted` = {$date_compiled}, `chat_player_mute_reason` = '{$chat_command_parsed_two[4]}' WHERE `chat_player_player_id` = {$chat_player_subject['id']} LIMIT 1");
98
  }
99
100
  /**
101
   * @param $delete
102
   */
103
  public static function db_chat_message_delete($delete) {
104
    doquery("DELETE FROM {{chat}} WHERE `messageid`={$delete};");
105
  }
106
107
  public static function db_chat_message_purge() {
108
    doquery("DELETE FROM `{{chat}}`;");
109
  }
110
111
  /**
112
   * @return array|bool|mysqli_result|null
113
   */
114
  public static function db_chat_message_get_last_25() {
115
    $query = doquery("SELECT * FROM `{{chat}}` ORDER BY messageid DESC LIMIT 25;");
116
117
    return $query;
118
  }
119
120
121
  /**
122
   * @param $player_id
123
   * @param $fields
124
   *
125
   * @return array|bool|mysqli_result|null
126
   */
127
  public static function db_chat_player_get($player_id, $fields) {
128
    return $result = doquery("SELECT {$fields} FROM {{chat_player}} WHERE `chat_player_player_id` = {$player_id} 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...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
129
  }
130
131
132
  /**
133
   * @param $player_id
134
   */
135
  public static function db_chat_player_insert($player_id) {
136
    doquery("INSERT INTO {{chat_player}} SET `chat_player_player_id` = {$player_id}");
137
  }
138
139
140
  /**
141
   * @param $user
142
   */
143
  public static function db_chat_player_update($user) {
144
    doquery("UPDATE {{chat_player}} SET `chat_player_refresh_last` = " . SN_TIME_NOW . " WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;");
145
  }
146
147
148
  /**
149
   * @param $alliance
150
   * @param $user
151
   *
152
   * @return array|bool|mysqli_result|null
153
   */
154
  public static function db_chat_list_select_advanced($alliance, $user) {
155
    $rows = doquery("SELECT count(1) AS CNT
156
          FROM {{chat}}
157
          WHERE
158
          (
159
            (ally_id = '{$alliance}' AND `chat_message_recipient_id` IS NULL) OR
160
            (ally_id = 0 AND `chat_message_recipient_id` = {$user['id']}) OR
161
            (ally_id = 0 AND `chat_message_sender_id` = {$user['id']} AND `chat_message_recipient_id` IS NOT NULL) OR
162
            (ally_id = 0 AND `chat_message_sender_id` IS NULL AND `chat_message_recipient_id` IS NULL)
163
          )
164
        ", 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...
165
166
    return $rows;
167
  }
168
169
170
  /**
171
   * @param $alliance
172
   * @param $user
173
   * @param $where_add
174
   * @param $start_row
175
   * @param $page_limit
176
   *
177
   * @return array|bool|mysqli_result|null
178
   */
179
  public static function db_chat_list_get_with_users($alliance, $user, $where_add, $start_row, $page_limit) {
180
    $query = doquery(
181
      "SELECT c.*, u.authlevel
182
        FROM
183
          {{chat}} AS c
184
          LEFT JOIN {{users}} AS u ON u.id = c.chat_message_sender_id
185
        WHERE
186
          (
187
            (c.ally_id = '{$alliance}' AND `chat_message_recipient_id` IS NULL) OR
188
            (c.ally_id = 0 AND `chat_message_recipient_id` = {$user['id']}) OR
189
            (c.ally_id = 0 AND `chat_message_sender_id` = {$user['id']} AND `chat_message_recipient_id` IS NOT NULL) OR
190
            (c.ally_id = 0 AND `chat_message_sender_id` IS NULL AND `chat_message_recipient_id` IS NULL)
191
          )
192
          {$where_add}
193
        ORDER BY messageid DESC
194
        LIMIT {$start_row}, {$page_limit}");
195
196
    return $query;
197
  }
198
199
  /**
200
   * @param $user
201
   *
202
   * @return array|bool|mysqli_result|null
203
   */
204
  public static function db_chat_player_select_id($user) {
205
    $activity_row = doquery("SELECT `chat_player_id` FROM {{chat_player}} WHERE `chat_player_player_id` = {$user['id']} 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...
206
207
    return $activity_row;
208
  }
209
210
211
  /**
212
   * @param $user
213
   */
214
  public static function db_chat_player_update_activity($user) {
215
    doquery("UPDATE {{chat_player}} SET `chat_player_activity` = '" . classSupernova::$db->db_escape(SN_TIME_SQL) . "' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1");
216
  }
217
218
}