Completed
Push — work-fleets ( 22b024...7f5906 )
by SuperNova.WS
06:37
created

db_ally_negotiatiion_delete_extended()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
ccs 0
cts 9
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->doUpdate("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 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}'");
13
  }
14
15
  public static function db_ally_request_get_by_user_id($player_id) {
16
    return classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$player_id}' LIMIT 1;");
17
  }
18
19
  public static function db_ally_count() {
20
    $result = classSupernova::$db->doSelectFetch('SELECT COUNT(`id`) AS ally_count FROM `{{alliance}}`');
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 = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` ='{$id_ally}' LIMIT 1");
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 = 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");
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 = classSupernova::$db->doSelectFetch("SELECT ally_tag FROM {{alliance}} WHERE `ally_tag` = '{$ally_tag}' or `ally_name` = '{$ally_name}' LIMIT 1;");
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 = classSupernova::$db->doInsert("INSERT INTO {{alliance}} SET
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
    return $ally;
76
  }
77
78
  /**
79
   * @param $ally_user_id
80
   * @param $ally_id
81
   */
82
  public static function db_ally_update_ally_user($ally_user_id, $ally_id) {
83
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET ally_user_id = {$ally_user_id} WHERE id = {$ally_id} LIMIT 1;");
84
  }
85
86
  /**
87
   * @param $user
88
   * @param $id_ally
89
   * @param $POST_text
90
   */
91
  public static function db_ally_request_insert($user, $id_ally, $POST_text) {
92
    classSupernova::$db->doInsert("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=" . SN_TIME_NOW . ";");
93
  }
94
95
  /**
96
   * @param $userId
97
   */
98
  public static function db_ally_request_delete_own($userId, $allyId) {
99
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_REQUEST, 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...
100
  }
101
102
103
  /**
104
   * @param $tag
105
   *
106
   * @return array|bool|mysqli_result|null
107
   */
108
  public static function db_ally_get_by_tag($tag) {
109
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;");
110
111
    return $ally;
112
  }
113
114
  /**
115
   * @param $ali_search_text
116
   *
117
   * @return array|bool|mysqli_result|null
118
   */
119
  public static function db_ally_search_by_name_or_tag($ali_search_text) {
120
    $search = classSupernova::$db->doSelect("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30");
121
122
    return $search;
123
  }
124
125
  /**
126
   * @param $ally
127
   *
128
   * @return array|bool|mysqli_result|null
129
   */
130
  public static function db_ally_request_count_by_id($ally) {
131
    $request = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'");
132
133
    return $request;
134
  }
135
136
137
  /**
138
   * @param $ally_changeset
139
   * @param $ally
140
   */
141
  public static function db_ally_update_by_changeset($ally_changeset, $ally) {
142
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;");
143
  }
144
145
  /**
146
   * @param $text_list
147
   * @param $allyTextID
148
   * @param $text
149
   * @param $ally
150
   */
151
  public static function db_ally_update_texts($text_list, $allyTextID, $text, $ally) {
152
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `{$text_list[$allyTextID]['db_field']}`='{$text['safe']}' WHERE `id`='{$ally['id']}';");
153
  }
154
155
  /**
156
   * @param $idNewLeader
157
   * @param $user
158
   */
159
  public static function db_ally_update_owner($idNewLeader, $user) {
160
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `ally_owner`='{$idNewLeader}' WHERE `id`={$user['ally_id']};");
161
  }
162
163
  /**
164
   * @param int $allyId
165
   */
166
  public static function db_ally_delete($allyId) {
167
    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...
168
  }
169
170
171
  /**
172
   * @param int $userAllyId
173
   * @param int $alliance_negotiation_contr_ally_id
174
   */
175
  public static function db_ally_negotiation_delete($userAllyId, $alliance_negotiation_contr_ally_id) {
176
    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...
177
      'alliance_negotiation_ally_id'       => $userAllyId,
178
      'alliance_negotiation_contr_ally_id' => $alliance_negotiation_contr_ally_id,
179
    ));
180
  }
181
182
  /**
183
   * @param $offer_id
184
   *
185
   * @return array|bool|mysqli_result|null
186
   */
187
  public static function db_ally_negotiation_get_by_offer_id($offer_id) {
188
    $negotiation = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
189
190
    return $negotiation;
191
  }
192
193
  /**
194
   * @param $offer_id
195
   */
196
  public static function db_ally_negotiation_delete_by_offer_id($offer_id) {
197
    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...
198
  }
199
200
  /**
201
   * @param $offer_id
202
   */
203
  public static function db_ally_negotiation_update_status_1($offer_id) {
204
    classSupernova::$db->doUpdate("UPDATE {{alliance_negotiation}} SET alliance_negotiation_status = 1 WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
205
  }
206
207
  /**
208
   * @param $negotiatorId
209
   * @param $userAllyId
210
   */
211
  public static function db_ally_negotiation_delete_extended($negotiatorId, $userAllyId) {
212
    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...
213
      'alliance_negotiation_id' => $negotiatorId,
214
      'alliance_negotiation_contr_ally_id' => $userAllyId,
215
    ));
216
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
217
      'alliance_negotiation_id' => $userAllyId,
218
      'alliance_negotiation_contr_ally_id' => $negotiatorId,
219
    ));
220
  }
221
222
  /**
223
   * @param $user
224
   *
225
   * @return array|bool|mysqli_result|null
226
   */
227
  public static function db_ally_list_get_by_not_user_ally($user) {
228
    $query = classSupernova::$db->doSelect("SELECT id, ally_name, ally_tag FROM {{alliance}} WHERE `id` != {$user['ally_id']} ORDER BY ally_name;");
229
230
    return $query;
231
  }
232
233
  /**
234
   * @param $user
235
   *
236
   * @return array|bool|mysqli_result|null
237
   */
238
  public static function db_ally_negotiation_list($user) {
239
    $query = classSupernova::$db->doSelect(
240
      "SELECT
241
        *,
242
        if(alliance_negotiation_ally_id = {$user['ally_id']}, 1, 0) AS owner,
243
        if(alliance_negotiation_ally_id = {$user['ally_id']}, alliance_negotiation_contr_ally_name, alliance_negotiation_ally_name) AS ally_name
244
      FROM
245
        {{alliance_negotiation}}
246
      WHERE
247
        alliance_negotiation_ally_id = {$user['ally_id']} OR alliance_negotiation_contr_ally_id = {$user['ally_id']};"
248
    );
249
250
    return $query;
251
  }
252
253
  /**
254
   * @param $d
255
   */
256
  public static function db_ally_request_deny($d) {
257
    classSupernova::$db->doUpdate("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '" . classLocale::$lang['ali_req_deny_reason'] . "' WHERE `id_user`= {$d} LIMIT 1;");
258
  }
259
260
  /**
261
   * @param $ally
262
   */
263
  public static function db_ally_update_member_increase($ally) {
264
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `ally_members`= `ally_members` + 1 WHERE `id`='{$ally['id']}'");
265
  }
266
267
  /**
268
   * @param $ally
269
   */
270
  public static function db_ally_update_member_decrease($ally) {
271
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `ally_members`= `ally_members` - 1 WHERE `id`='{$ally['id']}' LIMIT 1;");
272
  }
273
274
  /**
275
   * @param $i
276
   * @param $ally
277
   */
278
  public static function db_ally_update_member_set($i, $ally) {
279
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `ally_members`='{$i}' WHERE `id`='{$ally['id']}'");
280
  }
281
282
  /**
283
   * @param $id_user
284
   */
285
  public static function db_ally_request_delete_all_when_accepted($id_user) {
286
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_REQUEST, 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...
287
  }
288
289
290
  /**
291
   * @param $user
292
   *
293
   * @return array|bool|mysqli_result|null
294
   */
295
  public static function db_ally_get_members_by_user_as_ally(&$user) {
296
    $alliance = classSupernova::$db->doSelectFetch("SELECT `ally_members` FROM {{alliance}} WHERE `ally_user_id` = {$user['id']}");
297
298
    return $alliance;
299
  }
300
301
  /**
302
   * @param $ranklist
303
   * @param $user
304
   */
305
  public static function db_ally_update_ranklist($ranklist, $user) {
306
    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET `ranklist` = '{$ranklist}' WHERE `id` ='{$user['ally_id']}';");
307
  }
308
309
  /**
310
   * @param $ally_from
311
   * @param $ally_to
312
   *
313
   * @return array|bool|mysqli_result|null
314
   */
315
  public static function db_ally_diplomacy_get_relations($ally_from, $ally_to) {
316
    $query = classSupernova::$db->doSelect(
317
      "SELECT b.*
318
      FROM
319
        {{alliance_diplomacy}} AS b,
320
        (SELECT alliance_diplomacy_contr_ally_id, MAX(alliance_diplomacy_time) AS alliance_diplomacy_time
321
          FROM {{alliance_diplomacy}}
322
          WHERE alliance_diplomacy_ally_id = {$ally_from}  {$ally_to}
323
          GROUP BY alliance_diplomacy_ally_id, alliance_diplomacy_contr_ally_id
324
        ) AS m
325
      WHERE b.alliance_diplomacy_contr_ally_id = m.alliance_diplomacy_contr_ally_id
326
        AND b.alliance_diplomacy_time = m.alliance_diplomacy_time AND b.alliance_diplomacy_ally_id = {$ally_from}
327
      ORDER BY alliance_diplomacy_time, alliance_diplomacy_id;"
328
    );
329
330
    return $query;
331
  }
332
333
  /**
334
   * @param $user
335
   *
336
   * @return array|bool|mysqli_result|null
337
   */
338
  public static function db_ally_get_ally_count(&$user) {
339
    $lab_level = classSupernova::$db->doSelectFetch("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1");
340
341
    return $lab_level;
342
  }
343
344
}