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

DBStaticBuddy::db_buddy_delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
class DBStaticBuddy {
4
5
// BUDDY *************************************************************************************************************
6
7
  public static function db_buddy_insert($user, $new_friend_row, $new_request_text) {
8
    doquery("INSERT INTO {{buddy}} SET `BUDDY_SENDER_ID` = {$user['id']}, `BUDDY_OWNER_ID` = {$new_friend_row['id']}, `BUDDY_REQUEST` = '{$new_request_text}';");
9
  }
10
11
  public static function db_buddy_get_row($buddy_id) {
12
    return doquery("SELECT BUDDY_SENDER_ID, BUDDY_OWNER_ID, BUDDY_STATUS FROM {{buddy}} WHERE `BUDDY_ID` = {$buddy_id} LIMIT 1 FOR UPDATE;", 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...
13
  }
14
15
  public static function db_buddy_update_status($buddy_id, $status) {
16
    doquery("UPDATE {{buddy}} SET `BUDDY_STATUS` = {$status} WHERE `BUDDY_ID` = {$buddy_id} LIMIT 1;");
17
  }
18
19
  public static function db_buddy_delete($buddy_id) {
20
    doquery("DELETE FROM {{buddy}} WHERE `BUDDY_ID` = {$buddy_id} LIMIT 1;");
21
  }
22
23
  public static function db_buddy_check_relation($user, $new_friend_row) {
24
    return doquery("SELECT `BUDDY_ID` FROM {{buddy}} WHERE
25
      (`BUDDY_SENDER_ID` = {$user['id']} AND `BUDDY_OWNER_ID` = {$new_friend_row['id']})
26
      OR
27
      (`BUDDY_SENDER_ID` = {$new_friend_row['id']} AND `BUDDY_OWNER_ID` = {$user['id']})
28
      LIMIT 1 FOR UPDATE;"
29
      , 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...
30
  }
31
32
  public static function db_buddy_list_by_user($user_id) {
33
//  return ($user_id = intval($user_id)) ? doquery(
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...
34
    return ($user_id = idval($user_id)) ? doquery(
35
      "SELECT
36
      b.*,
37
      IF(b.BUDDY_OWNER_ID = {$user_id}, b.BUDDY_SENDER_ID, b.BUDDY_OWNER_ID) AS BUDDY_USER_ID,
38
      u.username AS BUDDY_USER_NAME,
39
      p.name AS BUDDY_PLANET_NAME,
40
      p.galaxy AS BUDDY_PLANET_GALAXY,
41
      p.system AS BUDDY_PLANET_SYSTEM,
42
      p.planet AS BUDDY_PLANET_PLANET,
43
      a.id AS BUDDY_ALLY_ID,
44
      a.ally_name AS BUDDY_ALLY_NAME,
45
      u.onlinetime
46
    FROM {{buddy}} AS b
47
      LEFT JOIN {{users}} AS u ON u.id = IF(b.BUDDY_OWNER_ID = {$user_id}, b.BUDDY_SENDER_ID, b.BUDDY_OWNER_ID)
48
      LEFT JOIN {{planets}} AS p ON p.id_owner = u.id AND p.id = id_planet
49
      LEFT JOIN {{alliance}} AS a ON a.id = u.ally_id
50
    WHERE (`BUDDY_OWNER_ID` = {$user_id}) OR `BUDDY_SENDER_ID` = {$user_id}
51
    ORDER BY BUDDY_STATUS, BUDDY_ID"
52
    ) : false;
53
  }
54
55
}