Completed
Push — work-fleets ( ea0fb4...874fb8 )
by SuperNova.WS
06:59
created

DBStaticAlly::db_ally_update_member_decrease()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
class DBStaticAlly {
4
5
// ALLY *************************************************************************************************************
6
  public static function db_ally_list_recalc_counts() {
7
    classSupernova::$db->doUpdateSqlNoParam(
8
      "UPDATE `{{alliance}}` AS a 
9
        LEFT JOIN (
10
          SELECT `ally_id`, count(*) AS ally_memeber_count 
11
          FROM `{{users}}`
12
          WHERE `ally_id` IS NOT NULL 
13
          GROUP BY ally_id
14
        ) AS u ON u.`ally_id` = a.`id` 
15
      SET 
16
        a.`ally_members` = u.ally_memeber_count;"
17
    );
18
  }
19
20
  public static function db_ally_request_list($ally_id) {
21
    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}'");
22
  }
23
24
  public static function db_ally_request_get_by_user_id($player_id) {
25
    return classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$player_id}' LIMIT 1;");
26
  }
27
28
  public static function db_ally_count() {
29
    $result = classSupernova::$db->doSelectFetch('SELECT COUNT(`id`) AS ally_count FROM `{{alliance}}`');
30
31
    return isset($result['ally_count']) ? $result['ally_count'] : 0;
32
  }
33
34
  /**
35
   * @param $id_ally
36
   *
37
   * @return array|bool|mysqli_result|null
38
   */
39
  public static function db_ally_get_by_id($id_ally) {
40
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` ='{$id_ally}' LIMIT 1");
41
42
    return $ally;
43
  }
44
45
  /**
46
   * @param $searchtext
47
   *
48
   * @return array|bool|mysqli_result|null
49
   */
50
  public static function db_ally_list_search($searchtext) {
51
    $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");
52
53
    return $search;
54
  }
55
56
  /**
57
   * @param $ally_tag
58
   * @param $ally_name
59
   *
60
   * @return array|bool|mysqli_result|null
61
   */
62
  public static function db_ally_get_by_name_or_tag($ally_tag, $ally_name) {
63
    $query = classSupernova::$db->doSelectFetch("SELECT ally_tag FROM {{alliance}} WHERE `ally_tag` = '{$ally_tag}' or `ally_name` = '{$ally_name}' LIMIT 1;");
64
65
    return $query;
66
  }
67
68
  /**
69
   * @param $ally_name_unsafe
70
   * @param $ally_tag_unsafe
71
   * @param $userId
72
   */
73
  public static function db_ally_insert($ally_name_unsafe, $ally_tag_unsafe, $userId) {
74
    $ally = classSupernova::$db->doInsertSet(TABLE_ALLIANCE, array(
75
      'ally_name'          => (string)$ally_name_unsafe,
76
      'ally_tag'           => (string)$ally_tag_unsafe,
77
      'ally_owner'         => $userId,
78
      'ally_owner_range'   => (string)classLocale::$lang['ali_leaderRank'],
79
      'ally_members'       => (int)1,
80
      'ranklist'           => (string)(classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0"),
81
      'ally_register_time' => SN_TIME_NOW,
82
    ));
83
84
    return $ally;
85
  }
86
87
  /**
88
   * @param $ally_user_id
89
   * @param $ally_id
90
   */
91
  public static function db_ally_update_ally_user($ally_user_id, $ally_id) {
92
    classSupernova::$db->doUpdateRowSet(
93
      TABLE_ALLIANCE,
94
      array(
95
        'ally_user_id' => $ally_user_id,
96
      ),
97
      array(
98
        'id' => $ally_id,
99
      )
100
    );
101
  }
102
103
  /**
104
   * @param int    $userId
105
   * @param int    $id_ally
106
   * @param string $requestTextUnsafe
107
   */
108
  public static function db_ally_request_insert($userId, $id_ally, $requestTextUnsafe) {
109
    classSupernova::$db->doInsertSet(TABLE_ALLIANCE_REQUESTS, array(
110
      'id_user'      => $userId,
111
      'id_ally'      => $id_ally,
112
      'request_text' => $requestTextUnsafe,
113
      'request_time' => SN_TIME_NOW,
114
    ));
115
  }
116
117
  /**
118
   * @param $userId
119
   */
120
  public static function db_ally_request_delete_own($userId, $allyId) {
121
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_REQUESTS, array('id_user' => $userId, 'id_ally' => $allyId,));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere 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...
122
  }
123
124
125
  /**
126
   * @param $tag
127
   *
128
   * @return array|bool|mysqli_result|null
129
   */
130
  public static function db_ally_get_by_tag($tag) {
131
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;");
132
133
    return $ally;
134
  }
135
136
  /**
137
   * @param $ali_search_text
138
   *
139
   * @return array|bool|mysqli_result|null
140
   */
141
  public static function db_ally_search_by_name_or_tag($ali_search_text) {
142
    $search = classSupernova::$db->doSelect("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30");
143
144
    return $search;
145
  }
146
147
  /**
148
   * @param $ally
149
   *
150
   * @return array|bool|mysqli_result|null
151
   */
152
  public static function db_ally_request_count_by_id($ally) {
153
    $request = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'");
154
155
    return $request;
156
  }
157
158
159
  /**
160
   * @param $ally_changeset
161
   * @param $ally
162
   */
163
  public static function db_ally_update_by_changeset($ally_changeset, $ally) {
164
    classSupernova::$db->doUpdateComplex("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;");
165
  }
166
167
  /**
168
   * @param $text_unsafe
169
   * @param $allyId
170
   * @param $fieldNameUnsafe
171
   */
172
  public static function db_ally_update_texts($text_unsafe, $allyId, $fieldNameUnsafe) {
173
    classSupernova::$db->doUpdateRowSet(
174
      TABLE_ALLIANCE,
175
      array(
176
        $fieldNameUnsafe => $text_unsafe,
177
      ),
178
      array(
179
        'id' => $allyId,
180
      )
181
    );
182
  }
183
184
  /**
185
   * @param $idNewLeader
186
   * @param $userAllyId
187
   */
188
  public static function db_ally_update_owner($idNewLeader, $userAllyId) {
189
    classSupernova::$db->doUpdateRowSet(
190
      TABLE_ALLIANCE,
191
      array(
192
        'ally_owner' => $idNewLeader,
193
      ),
194
      array(
195
        'id' => $userAllyId,
196
      )
197
    );
198
  }
199
200
  /**
201
   * @param int $allyId
202
   */
203
  public static function db_ally_delete($allyId) {
204
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE, array('id' => $allyId));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere 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...
205
  }
206
207
208
  /**
209
   * @param int $userAllyId
210
   * @param int $alliance_negotiation_contr_ally_id
211
   */
212
  public static function db_ally_negotiation_delete($userAllyId, $alliance_negotiation_contr_ally_id) {
213
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_NEGOTIATION, array(
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere 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...
214
      'alliance_negotiation_ally_id'       => $userAllyId,
215
      'alliance_negotiation_contr_ally_id' => $alliance_negotiation_contr_ally_id,
216
    ));
217
  }
218
219
  /**
220
   * @param $offer_id
221
   *
222
   * @return array|bool|mysqli_result|null
223
   */
224
  public static function db_ally_negotiation_get_by_offer_id($offer_id) {
225
    $negotiation = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
226
227
    return $negotiation;
228
  }
229
230
  /**
231
   * @param $offer_id
232
   */
233
  public static function db_ally_negotiation_delete_by_offer_id($offer_id) {
234
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_NEGOTIATION, array('alliance_negotiation_id' => $offer_id));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere 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...
235
  }
236
237
  /**
238
   * @param $offer_id
239
   */
240
  public static function db_ally_negotiation_deny($offer_id) {
241
    classSupernova::$db->doUpdateRowSet(
242
      TABLE_ALLIANCE_NEGOTIATION,
243
      array(
244
        'alliance_negotiation_status' => ALLY_PROPOSE_DENIED,
245
      ),
246
      array(
247
        'alliance_negotiation_id' => $offer_id,
248
      )
249
    );
250
  }
251
252
  /**
253
   * @param $negotiatorId
254
   * @param $userAllyId
255
   */
256
  public static function db_ally_negotiation_delete_extended($negotiatorId, $userAllyId) {
257
    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...
258
      'alliance_negotiation_id' => $negotiatorId,
259
      'alliance_negotiation_contr_ally_id' => $userAllyId,
260
    ));
261
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
262
      'alliance_negotiation_id' => $userAllyId,
263
      'alliance_negotiation_contr_ally_id' => $negotiatorId,
264
    ));
265
  }
266
267
  /**
268
   * @param $user
269
   *
270
   * @return array|bool|mysqli_result|null
271
   */
272
  public static function db_ally_list_get_by_not_user_ally($user) {
273
    $query = classSupernova::$db->doSelect("SELECT id, ally_name, ally_tag FROM {{alliance}} WHERE `id` != {$user['ally_id']} ORDER BY ally_name;");
274
275
    return $query;
276
  }
277
278
  /**
279
   * @param $user
280
   *
281
   * @return array|bool|mysqli_result|null
282
   */
283
  public static function db_ally_negotiation_list($user) {
284
    $query = classSupernova::$db->doSelect(
285
      "SELECT
286
        *,
287
        if(alliance_negotiation_ally_id = {$user['ally_id']}, 1, 0) AS owner,
288
        if(alliance_negotiation_ally_id = {$user['ally_id']}, alliance_negotiation_contr_ally_name, alliance_negotiation_ally_name) AS ally_name
289
      FROM
290
        {{alliance_negotiation}}
291
      WHERE
292
        alliance_negotiation_ally_id = {$user['ally_id']} OR alliance_negotiation_contr_ally_id = {$user['ally_id']};"
293
    );
294
295
    return $query;
296
  }
297
298
  /**
299
   * @param $id
300
   */
301
  public static function db_ally_request_deny($id) {
302
    classSupernova::$db->doUpdateRowSet(
303
      TABLE_ALLIANCE_REQUESTS,
304
      array(
305
        'request_denied' => ALLY_REQUEST_DENIED,
306
        'request_text' => classLocale::$lang['ali_req_deny_reason'],
307
      ),
308
      array(
309
        'id_user' => $id,
310
      )
311
    );
312
313
  }
314
315
  /**
316
   * @param $i
317
   * @param $allyId
318
   */
319
  public static function db_ally_update_member_set($i, $allyId) {
320
    classSupernova::$db->doUpdateRowSet(
321
      TABLE_ALLIANCE,
322
      array(
323
        'ally_members' => $i,
324
      ),
325
      array(
326
        'id' => $allyId,
327
      )
328
    );
329
  }
330
331
  /**
332
   * @param $id_user
333
   */
334
  public static function db_ally_request_delete_all_when_accepted($id_user) {
335
    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...
336
  }
337
338
339
  /**
340
   * @param $user
341
   *
342
   * @return array|bool|mysqli_result|null
343
   */
344
  public static function db_ally_get_members_by_user_as_ally(&$user) {
345
    $alliance = classSupernova::$db->doSelectFetch("SELECT `ally_members` FROM {{alliance}} WHERE `ally_user_id` = {$user['id']}");
346
347
    return $alliance;
348
  }
349
350
  /**
351
   * @param $ranklist
352
   * @param $userAllyId
353
   */
354
  public static function db_ally_update_ranklist($ranklist, $userAllyId) {
355
    classSupernova::$db->doUpdateRowSet(
356
      TABLE_ALLIANCE,
357
      array(
358
        'ranklist' => $ranklist,
359
      ),
360
      array(
361
        'id' => $userAllyId,
362
      )
363
    );
364
  }
365
366
  /**
367
   * @param $ally_from
368
   * @param $ally_to
369
   *
370
   * @return array|bool|mysqli_result|null
371
   */
372
  public static function db_ally_diplomacy_get_relations($ally_from, $ally_to) {
373
    $query = classSupernova::$db->doSelect(
374
      "SELECT b.*
375
      FROM
376
        {{alliance_diplomacy}} AS b,
377
        (SELECT alliance_diplomacy_contr_ally_id, MAX(alliance_diplomacy_time) AS alliance_diplomacy_time
378
          FROM {{alliance_diplomacy}}
379
          WHERE alliance_diplomacy_ally_id = {$ally_from}  {$ally_to}
380
          GROUP BY alliance_diplomacy_ally_id, alliance_diplomacy_contr_ally_id
381
        ) AS m
382
      WHERE b.alliance_diplomacy_contr_ally_id = m.alliance_diplomacy_contr_ally_id
383
        AND b.alliance_diplomacy_time = m.alliance_diplomacy_time AND b.alliance_diplomacy_ally_id = {$ally_from}
384
      ORDER BY alliance_diplomacy_time, alliance_diplomacy_id;"
385
    );
386
387
    return $query;
388
  }
389
390
  /**
391
   * @param $user
392
   *
393
   * @return array|bool|mysqli_result|null
394
   */
395
  public static function db_ally_get_ally_count(&$user) {
396
    $lab_level = classSupernova::$db->doSelectFetch("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1");
397
398
    return $lab_level;
399
  }
400
401
}