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

DBStaticAlly   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 336
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 336
rs 9
wmc 35
lcom 0
cbo 1

34 Methods

Rating   Name   Duplication   Size   Complexity  
A db_ally_list_recalc_counts() 0 4 1
A db_ally_request_list() 0 3 1
A db_ally_request_get_by_user_id() 0 3 1
A db_ally_count() 0 5 2
A db_ally_get_by_id() 0 5 1
A db_ally_list_search() 0 5 1
A db_ally_get_by_name_or_tag() 0 5 1
A db_ally_insert() 0 11 1
A db_ally_update_ally_user() 0 3 1
A db_ally_request_insert() 0 3 1
A db_ally_request_delete_by_user() 0 3 1
A db_ally_get_by_tag() 0 5 1
A db_ally_search_by_name_or_tag() 0 5 1
A db_ally_request_count_by_id() 0 5 1
A db_ally_update_by_changeset() 0 3 1
A db_ally_update_texts() 0 3 1
A db_ally_update_owner() 0 3 1
A db_ally_delete() 0 3 1
A db_ally_negotiation_delete() 0 3 1
A db_ally_negotiation_get_by_offer_id() 0 5 1
A db_ally_negotiation_delete_by_offer_id() 0 3 1
A db_ally_negotiation_update_status_1() 0 3 1
A db_ally_negotiatiion_delete_extended() 0 9 1
A db_ally_list_get_by_not_user_ally() 0 5 1
A db_ally_negotiation_list() 0 14 1
A db_ally_request_deny() 0 3 1
A db_ally_update_member_increase() 0 3 1
A db_ally_update_member_decrease() 0 3 1
A db_ally_update_member_set() 0 3 1
A db_ally_request_delete_by_user_id() 0 3 1
A db_ally_get_members_by_user_as_ally() 0 5 1
A db_ally_update_ranklist() 0 3 1
A db_ally_diplomacy_get_relations() 0 17 1
A db_ally_get_ally_count() 0 5 1
1
<?php
2
3
class DBStaticAlly {
4
5
// ALLY *************************************************************************************************************
6
  public static function db_ally_list_recalc_counts() {
7
    doquery("UPDATE `{{alliance}}` AS a LEFT JOIN (SELECT ally_id, count(*) AS ally_memeber_count FROM `{{users}}`
8
      WHERE ally_id IS NOT NULL GROUP BY ally_id) AS u ON u.ally_id = a.id SET a.`ally_members` = u.ally_memeber_count;");
9
  }
10
11
  public static function db_ally_request_list($ally_id) {
12
    return doquery("SELECT {{alliance_requests}}.*, {{users}}.username FROM {{alliance_requests}} LEFT JOIN {{users}} ON {{users}}.id = {{alliance_requests}}.id_user WHERE id_ally='{$ally_id}'");
13
  }
14
15
  public static function db_ally_request_get_by_user_id($player_id) {
16
    return doquery("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$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...
17
  }
18
19
  public static function db_ally_count() {
20
    $result = doquery('SELECT COUNT(`id`) AS ally_count FROM `{{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...
21
22
    return isset($result['ally_count']) ? $result['ally_count'] : 0;
23
  }
24
25
  /**
26
   * @param $id_ally
27
   *
28
   * @return array|bool|mysqli_result|null
29
   */
30
  public static function db_ally_get_by_id($id_ally) {
31
    $ally = doquery("SELECT * FROM `{{alliance}}` WHERE `id` ='{$id_ally}' 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...
32
33
    return $ally;
34
  }
35
36
  /**
37
   * @param $searchtext
38
   *
39
   * @return array|bool|mysqli_result|null
40
   */
41
  public static function db_ally_list_search($searchtext) {
42
    $search = doquery("SELECT ally_name, ally_tag, total_rank, ally_members FROM {{alliance}} WHERE ally_tag LIKE '%{$searchtext}%' OR ally_name LIKE '%{$searchtext}%' LIMIT 30");
43
44
    return $search;
45
  }
46
47
  /**
48
   * @param $ally_tag
49
   * @param $ally_name
50
   *
51
   * @return array|bool|mysqli_result|null
52
   */
53
  public static function db_ally_get_by_name_or_tag($ally_tag, $ally_name) {
54
    $query = doquery("SELECT ally_tag FROM {{alliance}} WHERE `ally_tag` = '{$ally_tag}' or `ally_name` = '{$ally_name}' 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...
55
56
    return $query;
57
  }
58
59
  /**
60
   * @param $ally_name
61
   * @param $ally_tag
62
   * @param $user
63
   */
64
  public static function db_ally_insert($ally_name, $ally_tag, $user) {
65
    $ally = doquery("INSERT INTO {{alliance}} SET
0 ignored issues
show
Unused Code introduced by
$ally 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...
66
    `ally_name` = '{$ally_name}',
67
    `ally_tag` = '{$ally_tag}',
68
    `ally_owner` = '{$user['id']}',
69
    `ally_owner_range` = '" . classLocale::$lang['ali_leaderRank'] . "',
70
    `ally_members` = 1,
71
    `ranklist` = '" . classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0',
72
    `ally_register_time`= " . SN_TIME_NOW
73
    );
74
  }
75
76
  /**
77
   * @param $ally_user_id
78
   * @param $ally_id
79
   */
80
  public static function db_ally_update_ally_user($ally_user_id, $ally_id) {
81
    doquery("UPDATE {{alliance}} SET ally_user_id = {$ally_user_id} WHERE id = {$ally_id} LIMIT 1;");
82
  }
83
84
  /**
85
   * @param $user
86
   * @param $id_ally
87
   * @param $POST_text
88
   */
89
  public static function db_ally_request_insert($user, $id_ally, $POST_text) {
90
    doquery("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=" . SN_TIME_NOW . ";");
91
  }
92
93
  /**
94
   * @param $user
95
   */
96
  public static function db_ally_request_delete_by_user($user) {
97
    doquery("DELETE FROM {{alliance_requests}} WHERE `id_user` = {$user['id']};");
98
  }
99
100
101
  /**
102
   * @param $tag
103
   *
104
   * @return array|bool|mysqli_result|null
105
   */
106
  public static function db_ally_get_by_tag($tag) {
107
    $ally = doquery("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;", '', true);
108
109
    return $ally;
110
  }
111
112
  /**
113
   * @param $ali_search_text
114
   *
115
   * @return array|bool|mysqli_result|null
116
   */
117
  public static function db_ally_search_by_name_or_tag($ali_search_text) {
118
    $search = doquery("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30");
119
120
    return $search;
121
  }
122
123
  /**
124
   * @param $ally
125
   *
126
   * @return array|bool|mysqli_result|null
127
   */
128
  public static function db_ally_request_count_by_id($ally) {
129
    $request = doquery("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'", 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...
130
131
    return $request;
132
  }
133
134
135
  /**
136
   * @param $ally_changeset
137
   * @param $ally
138
   */
139
  public static function db_ally_update_by_changeset($ally_changeset, $ally) {
140
    doquery("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;");
141
  }
142
143
  /**
144
   * @param $text_list
145
   * @param $allyTextID
146
   * @param $text
147
   * @param $ally
148
   */
149
  public static function db_ally_update_texts($text_list, $allyTextID, $text, $ally) {
150
    doquery("UPDATE {{alliance}} SET `{$text_list[$allyTextID]['db_field']}`='{$text['safe']}' WHERE `id`='{$ally['id']}';");
151
  }
152
153
  /**
154
   * @param $idNewLeader
155
   * @param $user
156
   */
157
  public static function db_ally_update_owner($idNewLeader, $user) {
158
    doquery("UPDATE {{alliance}} SET `ally_owner`='{$idNewLeader}' WHERE `id`={$user['ally_id']};");
159
  }
160
161
  /**
162
   * @param $ally
163
   */
164
  public static function db_ally_delete($ally) {
165
    doquery("DELETE FROM {{alliance}} WHERE id='{$ally['id']}';");
166
  }
167
168
169
  /**
170
   * @param $user
171
   * @param $alliance_negotiation_contr_ally_id
172
   */
173
  public static function db_ally_negotiation_delete($user, $alliance_negotiation_contr_ally_id) {
174
    doquery("DELETE FROM {{alliance_negotiation}} WHERE alliance_negotiation_ally_id = {$user['ally_id']} AND alliance_negotiation_contr_ally_id = {$alliance_negotiation_contr_ally_id} LIMIT 1;");
175
  }
176
177
  /**
178
   * @param $offer_id
179
   *
180
   * @return array|bool|mysqli_result|null
181
   */
182
  public static function db_ally_negotiation_get_by_offer_id($offer_id) {
183
    $negotiation = doquery("SELECT * FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;", '', true);
184
185
    return $negotiation;
186
  }
187
188
  /**
189
   * @param $offer_id
190
   */
191
  public static function db_ally_negotiation_delete_by_offer_id($offer_id) {
192
    doquery("DELETE FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
193
  }
194
195
  /**
196
   * @param $offer_id
197
   */
198
  public static function db_ally_negotiation_update_status_1($offer_id) {
199
    doquery("UPDATE {{alliance_negotiation}} SET alliance_negotiation_status = 1 WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
200
  }
201
202
  /**
203
   * @param $negotiation
204
   * @param $user
205
   */
206
  public static function db_ally_negotiatiion_delete_extended($negotiation, $user) {
207
    doquery(
208
      "DELETE FROM {{alliance_negotiation}}
209
  	 WHERE
210
        (alliance_negotiation_ally_id = {$negotiation['alliance_negotiation_ally_id']} AND alliance_negotiation_contr_ally_id = {$user['ally_id']})
211
        OR
212
        (alliance_negotiation_ally_id = {$user['ally_id']} AND alliance_negotiation_contr_ally_id = {$negotiation['alliance_negotiation_ally_id']});"
213
    );
214
  }
215
216
  /**
217
   * @param $user
218
   *
219
   * @return array|bool|mysqli_result|null
220
   */
221
  public static function db_ally_list_get_by_not_user_ally($user) {
222
    $query = doquery("SELECT id, ally_name, ally_tag FROM {{alliance}} WHERE `id` != {$user['ally_id']} ORDER BY ally_name;");
223
224
    return $query;
225
  }
226
227
  /**
228
   * @param $user
229
   *
230
   * @return array|bool|mysqli_result|null
231
   */
232
  public static function db_ally_negotiation_list($user) {
233
    $query = doquery(
234
      "SELECT
235
    *,
236
    if(alliance_negotiation_ally_id = {$user['ally_id']}, 1, 0) AS owner,
237
    if(alliance_negotiation_ally_id = {$user['ally_id']}, alliance_negotiation_contr_ally_name, alliance_negotiation_ally_name) AS ally_name
238
  FROM
239
    {{alliance_negotiation}}
240
  WHERE
241
    alliance_negotiation_ally_id = {$user['ally_id']} OR alliance_negotiation_contr_ally_id = {$user['ally_id']};"
242
    );
243
244
    return $query;
245
  }
246
247
  /**
248
   * @param $d
249
   */
250
  public static function db_ally_request_deny($d) {
251
    doquery("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '" . classLocale::$lang['ali_req_deny_reason'] . "' WHERE `id_user`= {$d} LIMIT 1;");
252
  }
253
254
  /**
255
   * @param $ally
256
   */
257
  public static function db_ally_update_member_increase($ally) {
258
    doquery("UPDATE {{alliance}} SET `ally_members`= `ally_members` + 1 WHERE `id`='{$ally['id']}'");
259
  }
260
261
  /**
262
   * @param $ally
263
   */
264
  public static function db_ally_update_member_decrease($ally) {
265
    doquery("UPDATE {{alliance}} SET `ally_members`= `ally_members` - 1 WHERE `id`='{$ally['id']}' LIMIT 1;");
266
  }
267
268
  /**
269
   * @param $i
270
   * @param $ally
271
   */
272
  public static function db_ally_update_member_set($i, $ally) {
273
    doquery("UPDATE {{alliance}} SET `ally_members`='{$i}' WHERE `id`='{$ally['id']}'");
274
  }
275
276
  /**
277
   * @param $id_user
278
   */
279
  public static function db_ally_request_delete_by_user_id($id_user) {
280
    doquery("DELETE FROM {{alliance_requests}} WHERE `id_user`= '{$id_user}' LIMIT 1;");
281
  }
282
283
284
  /**
285
   * @param $user
286
   *
287
   * @return array|bool|mysqli_result|null
288
   */
289
  public static function db_ally_get_members_by_user_as_ally(&$user) {
290
    $alliance = doquery("SELECT `ally_members` FROM {{alliance}} WHERE `ally_user_id` = {$user['id']}", 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...
291
292
    return $alliance;
293
  }
294
295
  /**
296
   * @param $ranklist
297
   * @param $user
298
   */
299
  public static function db_ally_update_ranklist($ranklist, $user) {
300
    doquery("UPDATE {{alliance}} SET `ranklist` = '{$ranklist}' WHERE `id` ='{$user['ally_id']}';");
301
  }
302
303
  /**
304
   * @param $ally_from
305
   * @param $ally_to
306
   *
307
   * @return array|bool|mysqli_result|null
308
   */
309
  public static function db_ally_diplomacy_get_relations($ally_from, $ally_to) {
310
    $query = doquery(
311
      "SELECT b.*
312
      FROM
313
        {{alliance_diplomacy}} AS b,
314
        (SELECT alliance_diplomacy_contr_ally_id, MAX(alliance_diplomacy_time) AS alliance_diplomacy_time
315
          FROM {{alliance_diplomacy}}
316
          WHERE alliance_diplomacy_ally_id = {$ally_from}  {$ally_to}
317
          GROUP BY alliance_diplomacy_ally_id, alliance_diplomacy_contr_ally_id
318
        ) AS m
319
      WHERE b.alliance_diplomacy_contr_ally_id = m.alliance_diplomacy_contr_ally_id
320
        AND b.alliance_diplomacy_time = m.alliance_diplomacy_time AND b.alliance_diplomacy_ally_id = {$ally_from}
321
      ORDER BY alliance_diplomacy_time, alliance_diplomacy_id;"
322
    );
323
324
    return $query;
325
  }
326
327
  /**
328
   * @param $user
329
   *
330
   * @return array|bool|mysqli_result|null
331
   */
332
  public static function db_ally_get_ally_count(&$user) {
333
    $lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} 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...
334
335
    return $lab_level;
336
  }
337
338
}