Completed
Push — work-fleets ( 4aef09...b4179a )
by SuperNova.WS
05:37
created

DBStaticMessages   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 101
rs 10
c 1
b 0
f 0
wmc 16
lcom 0
cbo 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A db_message_list_get_last_20() 0 9 1
A db_message_list_delete() 0 3 1
A db_message_list_outbox_by_user_id() 0 10 2
A db_message_list_by_owner_and_string() 0 3 1
A db_message_count_by_owner_and_type() 0 3 1
A db_message_count_outbox() 0 5 1
A db_message_list_admin_by_type() 0 17 2
A db_message_insert_all() 0 4 1
A db_message_count_by_type() 0 5 2
A db_message_list_delete_set() 0 3 1
A db_message_list_delete_by_date() 0 3 2
A db_message_insert() 0 4 1
1
<?php
2
3
class DBStaticMessages {
4
5
// Messages *************************************************************************************************************
6
  public static function db_message_list_get_last_20($user, $recipient_id) {
7
    return doquery(
8
      "SELECT * FROM {{messages}}
9
        WHERE
10
          `message_type` = '" . MSG_TYPE_PLAYER . "' AND
11
          ((`message_owner` = '{$user['id']}' AND `message_sender` = '{$recipient_id}')
12
          OR
13
          (`message_sender` = '{$user['id']}' AND `message_owner` = '{$recipient_id}')) ORDER BY `message_time` DESC LIMIT 20;");
14
  }
15
16
  public static function db_message_list_delete($user, $query_add) {
17
    doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '{$user['id']}'{$query_add};");
18
  }
19
20
  public static function db_message_list_outbox_by_user_id($user_id) {
21
    // return ($user_id = intval($user_id))
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
22
    return ($user_id = idval($user_id))
23
      ? doquery("SELECT {{messages}}.message_id, {{messages}}.message_owner, {{users}}.id AS message_sender, {{messages}}.message_time,
24
          {{messages}}.message_type, {{users}}.username AS message_from, {{messages}}.message_subject, {{messages}}.message_text
25
       FROM
26
         {{messages}} LEFT JOIN {{users}} ON {{users}}.id = {{messages}}.message_owner WHERE `message_sender` = '{$user_id}' AND `message_type` = 1
27
       ORDER BY `message_time` DESC;")
28
      : false;
29
  }
30
31
  public static function db_message_list_by_owner_and_string($user, $SubSelectQry) {
32
    return doquery("SELECT * FROM {{messages}} WHERE `message_owner` = '{$user['id']}' {$SubSelectQry} ORDER BY `message_time` DESC;");
33
  }
34
35
  public static function db_message_count_by_owner_and_type($user) {
36
    return doquery("SELECT message_owner, message_type, COUNT(message_owner) AS message_count FROM {{messages}} WHERE `message_owner` = {$user['id']} GROUP BY message_owner, message_type ORDER BY message_owner ASC, message_type;");
37
  }
38
39
  public static function db_message_count_outbox($user) {
40
    $row = doquery("SELECT COUNT(message_sender) AS message_count FROM {{messages}} WHERE `message_sender` = '{$user['id']}' AND message_type = 1 GROUP BY message_sender;", 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...
41
42
    return intval($row['message_count']);
43
  }
44
45
  public static function db_message_list_admin_by_type($int_type_selected, $StartRec) {
46
    return doquery("SELECT
47
  message_id as `ID`,
48
  message_from as `FROM`,
49
  message_owner as `OWNER_ID`,
50
  u.username as `OWNER_NAME`,
51
  message_text as `TEXT`,
52
  FROM_UNIXTIME(message_time) as `TIME`
53
FROM
54
  {{messages}} AS m
55
  LEFT JOIN {{users}} AS u ON u.id = m.message_owner " .
56
      ($int_type_selected >= 0 ? "WHERE `message_type` = {$int_type_selected} " : '') .
57
      "ORDER BY
58
  `message_id` DESC
59
LIMIT
60
  {$StartRec}, 25;");
61
  }
62
63
  public static function db_message_insert_all($message_type, $from, $subject, $text) {
64
    return doquery($QryInsertMessage = 'INSERT INTO {{messages}} (`message_owner`, `message_sender`, `message_time`, `message_type`, `message_from`, `message_subject`, `message_text`) ' .
65
      "SELECT `id`, 0, unix_timestamp(now()), {$message_type}, '{$from}', '{$subject}', '{$text}' FROM {{users}}");
66
  }
67
68
  /**
69
   * @param $int_type_selected
70
   *
71
   * @return array|bool|mysqli_result|null
72
   */
73
  public static function db_message_count_by_type($int_type_selected) {
74
    $page_max = doquery('SELECT COUNT(*) AS `max` FROM {{messages}}' . ($int_type_selected >= 0 ? " WHERE `message_type` = {$int_type_selected};" : ''), 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...
75
76
    return $page_max;
77
  }
78
79
  /**
80
   * @param $message_delete
81
   */
82
  public static function db_message_list_delete_set($message_delete) {
83
    doquery("DELETE FROM {{messages}} WHERE `message_id` in ({$message_delete});");
84
  }
85
86
  /**
87
   * @param $delete_date
88
   * @param $int_type_selected
89
   */
90
  public static function db_message_list_delete_by_date($delete_date, $int_type_selected) {
91
    doquery("DELETE FROM {{messages}} WHERE message_time <= UNIX_TIMESTAMP('{$delete_date}')" . ($int_type_selected >= 0 ? " AND `message_type` = {$int_type_selected}" : ''));
92
  }
93
94
  /**
95
   * @param $insert_values
96
   */
97
  public static function db_message_insert($insert_values) {
98
    doquery('INSERT INTO {{messages}} (`message_owner`, `message_sender`, `message_time`, `message_type`, `message_from`, `message_subject`, `message_text`) ' .
99
      'VALUES ' . implode(',', $insert_values));
100
  }
101
102
103
}