Completed
Push — work-fleets ( d7065d...1ee481 )
by SuperNova.WS
08:22
created

DBStaticAlly   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 410
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 410
ccs 0
cts 237
cp 0
rs 9.6
wmc 32
lcom 0
cbo 4

31 Methods

Rating   Name   Duplication   Size   Complexity  
A db_ally_list_recalc_counts() 0 13 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 13 1
A db_ally_update_ally_user() 0 11 1
A db_ally_request_insert() 0 8 1
A db_ally_request_delete_own() 0 9 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_texts() 0 11 1
A db_ally_update_owner() 0 11 1
A db_ally_delete() 0 8 1
A db_ally_negotiation_delete() 0 9 1
A db_ally_negotiation_get_by_offer_id() 0 5 1
A db_ally_negotiation_delete_by_offer_id() 0 8 1
A db_ally_negotiation_deny() 0 11 1
A db_ally_negotiation_delete_extended() 0 10 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 13 1
A db_ally_update_member_set() 0 11 1
A db_ally_request_delete_all_when_accepted() 0 3 1
A db_ally_get_members_by_user_as_ally() 0 5 1
A db_ally_update_ranklist() 0 11 1
A db_ally_diplomacy_get_relations() 0 17 1
A db_ally_get_ally_count() 0 5 1
1
<?php
2
3
namespace DBStatic;
4
use classLocale;
5
use classSupernova;
6
use mysqli_result;
7
8
class DBStaticAlly {
9
10
// ALLY *************************************************************************************************************
11
  public static function db_ally_list_recalc_counts() {
12
    classSupernova::$db->doUpdateSqlNoParam(
13
      "UPDATE `{{alliance}}` AS a 
14
        LEFT JOIN (
15
          SELECT `ally_id`, count(*) AS ally_memeber_count 
16
          FROM `{{users}}`
17
          WHERE `ally_id` IS NOT NULL 
18
          GROUP BY ally_id
19
        ) AS u ON u.`ally_id` = a.`id` 
20
      SET 
21
        a.`ally_members` = u.ally_memeber_count;"
22
    );
23
  }
24
25
  public static function db_ally_request_list($ally_id) {
26
    return classSupernova::$db->doSelect("SELECT {{alliance_requests}}.*, {{users}}.username FROM {{alliance_requests}} LEFT JOIN {{users}} ON {{users}}.id = {{alliance_requests}}.id_user WHERE id_ally='{$ally_id}'");
27
  }
28
29
  public static function db_ally_request_get_by_user_id($player_id) {
30
    return classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$player_id}' LIMIT 1;");
31
  }
32
33
  public static function db_ally_count() {
34
    $result = classSupernova::$db->doSelectFetch('SELECT COUNT(`id`) AS ally_count FROM `{{alliance}}`');
35
36
    return isset($result['ally_count']) ? $result['ally_count'] : 0;
37
  }
38
39
  /**
40
   * @param $id_ally
41
   *
42
   * @return array|bool|mysqli_result|null
43
   */
44
  public static function db_ally_get_by_id($id_ally) {
45
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` ='{$id_ally}' LIMIT 1");
46
47
    return $ally;
48
  }
49
50
  /**
51
   * @param $searchtext
52
   *
53
   * @return array|bool|mysqli_result|null
54
   */
55
  public static function db_ally_list_search($searchtext) {
56
    $search = classSupernova::$db->doSelect("SELECT ally_name, ally_tag, total_rank, ally_members FROM {{alliance}} WHERE ally_tag LIKE '%{$searchtext}%' OR ally_name LIKE '%{$searchtext}%' LIMIT 30");
57
58
    return $search;
59
  }
60
61
  /**
62
   * @param $ally_tag
63
   * @param $ally_name
64
   *
65
   * @return array|bool|mysqli_result|null
66
   */
67
  public static function db_ally_get_by_name_or_tag($ally_tag, $ally_name) {
68
    $query = classSupernova::$db->doSelectFetch("SELECT ally_tag FROM {{alliance}} WHERE `ally_tag` = '{$ally_tag}' or `ally_name` = '{$ally_name}' LIMIT 1;");
69
70
    return $query;
71
  }
72
73
  /**
74
   * @param $ally_name_unsafe
75
   * @param $ally_tag_unsafe
76
   * @param $userId
77
   */
78
  public static function db_ally_insert($ally_name_unsafe, $ally_tag_unsafe, $userId) {
79
    $ally = classSupernova::$db->doInsertSet(TABLE_ALLIANCE, array(
80
      'ally_name'          => (string)$ally_name_unsafe,
81
      'ally_tag'           => (string)$ally_tag_unsafe,
82
      'ally_owner'         => $userId,
83
      'ally_owner_range'   => (string)classLocale::$lang['ali_leaderRank'],
84
      'ally_members'       => (int)1,
85
      'ranklist'           => (string)(classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0"),
86
      'ally_register_time' => SN_TIME_NOW,
87
    ));
88
89
    return $ally;
90
  }
91
92
  /**
93
   * @param $ally_user_id
94
   * @param $ally_id
95
   */
96
  public static function db_ally_update_ally_user($ally_user_id, $ally_id) {
97
    classSupernova::$db->doUpdateRowSet(
98
      TABLE_ALLIANCE,
99
      array(
100
        'ally_user_id' => $ally_user_id,
101
      ),
102
      array(
103
        'id' => $ally_id,
104
      )
105
    );
106
  }
107
108
  /**
109
   * @param int    $userId
110
   * @param int    $id_ally
111
   * @param string $requestTextUnsafe
112
   */
113
  public static function db_ally_request_insert($userId, $id_ally, $requestTextUnsafe) {
114
    classSupernova::$db->doInsertSet(TABLE_ALLIANCE_REQUESTS, array(
115
      'id_user'      => $userId,
116
      'id_ally'      => $id_ally,
117
      'request_text' => $requestTextUnsafe,
118
      'request_time' => SN_TIME_NOW,
119
    ));
120
  }
121
122
  /**
123
   * @param $userId
124
   */
125
  public static function db_ally_request_delete_own($userId, $allyId) {
126
    classSupernova::$gc->db->doDeleteRow(
0 ignored issues
show
Bug introduced by
The method doDeleteRow does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
      TABLE_ALLIANCE_REQUESTS,
128
      array(
129
        'id_user' => $userId,
130
        'id_ally' => $allyId,
131
      )
132
    );
133
  }
134
135
136
  /**
137
   * @param $tag
138
   *
139
   * @return array|bool|mysqli_result|null
140
   */
141
  public static function db_ally_get_by_tag($tag) {
142
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;");
143
144
    return $ally;
145
  }
146
147
  /**
148
   * @param $ali_search_text
149
   *
150
   * @return array|bool|mysqli_result|null
151
   */
152
  public static function db_ally_search_by_name_or_tag($ali_search_text) {
153
    $search = classSupernova::$db->doSelect("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30");
154
155
    return $search;
156
  }
157
158
  /**
159
   * @param $ally
160
   *
161
   * @return array|bool|mysqli_result|null
162
   */
163
  public static function db_ally_request_count_by_id($ally) {
164
    $request = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'");
165
166
    return $request;
167
  }
168
169
170
  /**
171
   * @param $text_unsafe
172
   * @param $allyId
173
   * @param $fieldNameUnsafe
174
   */
175
  public static function db_ally_update_texts($text_unsafe, $allyId, $fieldNameUnsafe) {
176
    classSupernova::$db->doUpdateRowSet(
177
      TABLE_ALLIANCE,
178
      array(
179
        $fieldNameUnsafe => $text_unsafe,
180
      ),
181
      array(
182
        'id' => $allyId,
183
      )
184
    );
185
  }
186
187
  /**
188
   * @param $idNewLeader
189
   * @param $userAllyId
190
   */
191
  public static function db_ally_update_owner($idNewLeader, $userAllyId) {
192
    classSupernova::$db->doUpdateRowSet(
193
      TABLE_ALLIANCE,
194
      array(
195
        'ally_owner' => $idNewLeader,
196
      ),
197
      array(
198
        'id' => $userAllyId,
199
      )
200
    );
201
  }
202
203
  /**
204
   * @param int $allyId
205
   */
206
  public static function db_ally_delete($allyId) {
207
    classSupernova::$gc->db->doDeleteRow(
0 ignored issues
show
Bug introduced by
The method doDeleteRow does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
208
      TABLE_ALLIANCE,
209
      array(
210
        'id' => $allyId,
211
      )
212
    );
213
  }
214
215
216
  /**
217
   * @param int $userAllyId
218
   * @param int $alliance_negotiation_contr_ally_id
219
   */
220
  public static function db_ally_negotiation_delete($userAllyId, $alliance_negotiation_contr_ally_id) {
221
    classSupernova::$gc->db->doDeleteRow(
0 ignored issues
show
Bug introduced by
The method doDeleteRow does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
222
      TABLE_ALLIANCE_NEGOTIATION,
223
      array(
224
        'alliance_negotiation_ally_id'       => $userAllyId,
225
        'alliance_negotiation_contr_ally_id' => $alliance_negotiation_contr_ally_id,
226
      )
227
    );
228
  }
229
230
  /**
231
   * @param $offer_id
232
   *
233
   * @return array|bool|mysqli_result|null
234
   */
235
  public static function db_ally_negotiation_get_by_offer_id($offer_id) {
236
    $negotiation = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
237
238
    return $negotiation;
239
  }
240
241
  /**
242
   * @param $offer_id
243
   */
244
  public static function db_ally_negotiation_delete_by_offer_id($offer_id) {
245
    classSupernova::$gc->db->doDeleteRow(
0 ignored issues
show
Bug introduced by
The method doDeleteRow does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
246
      TABLE_ALLIANCE_NEGOTIATION,
247
      array(
248
        'alliance_negotiation_id' => $offer_id,
249
      )
250
    );
251
  }
252
253
  /**
254
   * @param $offer_id
255
   */
256
  public static function db_ally_negotiation_deny($offer_id) {
257
    classSupernova::$db->doUpdateRowSet(
258
      TABLE_ALLIANCE_NEGOTIATION,
259
      array(
260
        'alliance_negotiation_status' => ALLY_PROPOSE_DENIED,
261
      ),
262
      array(
263
        'alliance_negotiation_id' => $offer_id,
264
      )
265
    );
266
  }
267
268
  /**
269
   * @param $negotiatorId
270
   * @param $userAllyId
271
   */
272
  public static function db_ally_negotiation_delete_extended($negotiatorId, $userAllyId) {
273
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
274
      'alliance_negotiation_id'            => $negotiatorId,
275
      'alliance_negotiation_contr_ally_id' => $userAllyId,
276
    ));
277
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
278
      'alliance_negotiation_id'            => $userAllyId,
279
      'alliance_negotiation_contr_ally_id' => $negotiatorId,
280
    ));
281
  }
282
283
  /**
284
   * @param $user
285
   *
286
   * @return array|bool|mysqli_result|null
287
   */
288
  public static function db_ally_list_get_by_not_user_ally($user) {
289
    $query = classSupernova::$db->doSelect("SELECT id, ally_name, ally_tag FROM {{alliance}} WHERE `id` != {$user['ally_id']} ORDER BY ally_name;");
290
291
    return $query;
292
  }
293
294
  /**
295
   * @param $user
296
   *
297
   * @return array|bool|mysqli_result|null
298
   */
299
  public static function db_ally_negotiation_list($user) {
300
    $query = classSupernova::$db->doSelect(
301
      "SELECT
302
        *,
303
        if(alliance_negotiation_ally_id = {$user['ally_id']}, 1, 0) AS owner,
304
        if(alliance_negotiation_ally_id = {$user['ally_id']}, alliance_negotiation_contr_ally_name, alliance_negotiation_ally_name) AS ally_name
305
      FROM
306
        {{alliance_negotiation}}
307
      WHERE
308
        alliance_negotiation_ally_id = {$user['ally_id']} OR alliance_negotiation_contr_ally_id = {$user['ally_id']};"
309
    );
310
311
    return $query;
312
  }
313
314
  /**
315
   * @param $id
316
   */
317
  public static function db_ally_request_deny($id) {
318
    classSupernova::$db->doUpdateRowSet(
319
      TABLE_ALLIANCE_REQUESTS,
320
      array(
321
        'request_denied' => ALLY_REQUEST_DENIED,
322
        'request_text'   => classLocale::$lang['ali_req_deny_reason'],
323
      ),
324
      array(
325
        'id_user' => $id,
326
      )
327
    );
328
329
  }
330
331
  /**
332
   * @param $i
333
   * @param $allyId
334
   */
335
  public static function db_ally_update_member_set($i, $allyId) {
336
    classSupernova::$db->doUpdateRowSet(
337
      TABLE_ALLIANCE,
338
      array(
339
        'ally_members' => $i,
340
      ),
341
      array(
342
        'id' => $allyId,
343
      )
344
    );
345
  }
346
347
  /**
348
   * @param $id_user
349
   */
350
  public static function db_ally_request_delete_all_when_accepted($id_user) {
351
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_REQUESTS, array('id_user' => $id_user));
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
352
  }
353
354
355
  /**
356
   * @param $user
357
   *
358
   * @return array|bool|mysqli_result|null
359
   */
360
  public static function db_ally_get_members_by_user_as_ally(&$user) {
361
    $alliance = classSupernova::$db->doSelectFetch("SELECT `ally_members` FROM {{alliance}} WHERE `ally_user_id` = {$user['id']}");
362
363
    return $alliance;
364
  }
365
366
  /**
367
   * @param $ranklist
368
   * @param $userAllyId
369
   */
370
  public static function db_ally_update_ranklist($ranklist, $userAllyId) {
371
    classSupernova::$db->doUpdateRowSet(
372
      TABLE_ALLIANCE,
373
      array(
374
        'ranklist' => $ranklist,
375
      ),
376
      array(
377
        'id' => $userAllyId,
378
      )
379
    );
380
  }
381
382
  /**
383
   * @param $ally_from
384
   * @param $ally_to
385
   *
386
   * @return array|bool|mysqli_result|null
387
   */
388
  public static function db_ally_diplomacy_get_relations($ally_from, $ally_to) {
389
    $query = classSupernova::$db->doSelect(
390
      "SELECT b.*
391
      FROM
392
        {{alliance_diplomacy}} AS b,
393
        (SELECT alliance_diplomacy_contr_ally_id, MAX(alliance_diplomacy_time) AS alliance_diplomacy_time
394
          FROM {{alliance_diplomacy}}
395
          WHERE alliance_diplomacy_ally_id = {$ally_from}  {$ally_to}
396
          GROUP BY alliance_diplomacy_ally_id, alliance_diplomacy_contr_ally_id
397
        ) AS m
398
      WHERE b.alliance_diplomacy_contr_ally_id = m.alliance_diplomacy_contr_ally_id
399
        AND b.alliance_diplomacy_time = m.alliance_diplomacy_time AND b.alliance_diplomacy_ally_id = {$ally_from}
400
      ORDER BY alliance_diplomacy_time, alliance_diplomacy_id;"
401
    );
402
403
    return $query;
404
  }
405
406
  /**
407
   * @param $user
408
   *
409
   * @return array|bool|mysqli_result|null
410
   */
411
  public static function db_ally_get_ally_count(&$user) {
412
    $lab_level = classSupernova::$db->doSelectFetch("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1");
413
414
    return $lab_level;
415
  }
416
417
}