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

DBStaticNews::db_news_insert_set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 2
rs 9.6666
1
<?php
2
3
namespace DBStatic;
4
use classSupernova;
5
use mysqli_result;
6
use template;
7
8
class DBStaticNews {
9
10
  public static function db_news_update_set($announce_time, $text_unsafe, $detail_url_unsafe, $announce_id) {
11
    classSupernova::$db->doUpdateRowSet(
12
      TABLE_ANNOUNCE,
13
      array(
14
        'tsTimeStamp' => date(FMT_DATE_TIME_SQL, $announce_time),
15
        'strAnnounce' => $text_unsafe,
16
        'detail_url'  => $detail_url_unsafe,
17
      ),
18
      array(
19
        'idAnnounce' => $announce_id,
20
      )
21
    );
22
  }
23
24
  public static function db_news_insert_set($announce_time, $text_unsafe, $detail_url_unsafe, $userId, $userNameUnsafe) {
25
    classSupernova::$db->doInsertSet(TABLE_ANNOUNCE, array(
26
      'tsTimeStamp' => date(FMT_DATE_TIME_SQL, $announce_time),
27
      'strAnnounce' => $text_unsafe,
28
      'detail_url'  => $detail_url_unsafe,
29
      'user_id'     => $userId,
30
      'user_name'   => $userNameUnsafe,
31
    ));
32
  }
33
34
  public static function db_news_delete_by_id($announce_id) {
35
    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...
36
      TABLE_ANNOUNCE,
37
      array(
38
        'idAnnounce' => $announce_id,
39
      )
40
    );
41
  }
42
43
  public static function db_news_with_survey_select_by_id($announce_id) {
44
    return classSupernova::$db->doSelectFetch(
45
      "SELECT a.*, s.survey_id, s.survey_question, s.survey_until
46
        FROM {{announce}} AS a
47
        LEFT JOIN {{survey}} AS s ON s.survey_announce_id = a.idAnnounce
48
        WHERE `idAnnounce` = {$announce_id} LIMIT 1;");
49
  }
50
51
  /**
52
   * @param template $template
53
   * @param          $query_where
54
   * @param          $query_limit
55
   *
56
   * @return array|bool|mysqli_result|null
57
   */
58
  public static function db_news_list_get_by_query(&$template, $query_where, $query_limit) {
59
    $announce_list = classSupernova::$db->doSelect(
60
      "SELECT a.*, UNIX_TIMESTAMP(`tsTimeStamp`) AS unix_time, u.authlevel, s.*
61
    FROM
62
      {{announce}} AS a
63
      LEFT JOIN {{survey}} AS s ON s.survey_announce_id = a.idAnnounce
64
      LEFT JOIN {{users}} AS u ON u.id = a.user_id
65
    {$query_where}
66
    ORDER BY `tsTimeStamp` DESC, idAnnounce" .
67
      ($query_limit ? " LIMIT {$query_limit}" : ''));
68
69
    $template->assign_var('NEWS_COUNT', classSupernova::$db->db_num_rows($announce_list));
70
71
    return $announce_list;
72
  }
73
74
}
75