Completed
Push — work-fleets ( b19a67...de8005 )
by SuperNova.WS
06:26
created

DbRowSimple::insert()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 4
nop 1
dl 0
loc 23
rs 9.0856
c 2
b 0
f 0
1
<?php
2
3
class DbRowSimple {
4
5
  /**
6
   * @param Entity $object
7
   * @param mixed  $rowId
8
   *
9
   * @return Entity
10
   */
11
  public function getById($object, $rowId) {
12
    $stmt = classSupernova::$gc->query
0 ignored issues
show
Bug introduced by
The method setIdField cannot be called on \classSupernova::$gc->query (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
13
      ->setIdField($object::$idField)
14
      ->field('*')
15
      ->from($object::$tableName)
16
      ->where($object::$idField . ' = "' . $rowId . '"');
17
18
    $object->setRow($stmt->selectRow());
19
20
    return $object;
21
  }
22
23
  /**
24
   * @param Entity $object
25
   */
26
  public function deleteById($object) {
27
    $db = classSupernova::$gc->db;
28
29
    $db->doquery("DELETE FROM `{{" . $object::$tableName . "}}` WHERE `{$object::$idField}` = '{$object->getDbId()}' LIMIT 1;");
0 ignored issues
show
Bug introduced by
The method doquery 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...
30
31
    return $db->db_affected_rows();
0 ignored issues
show
Bug introduced by
The method db_affected_rows 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...
32
  }
33
34
  /**
35
   * @param Entity $object
36
   */
37
  public function insert($object) {
38
    $db = classSupernova::$gc->db;
39
40
    $query = array();
41
    foreach ($object->getRow(false) as $fieldName => $fieldValue) {
42
      $fieldValue = $db->db_escape($fieldValue);
0 ignored issues
show
Bug introduced by
The method db_escape 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...
43
      $query[] = "`{$fieldName}` = '{$fieldValue}'";
44
    }
45
46
    $query = implode(',', $query);
47
    if (empty($query)) {
48
      // TODO Exceptiion
49
      return 0;
50
    }
51
52
    $db->doquery("INSERT INTO `{{" . $object::$tableName . "}}` SET " . $query);
0 ignored issues
show
Bug introduced by
The method doquery 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...
53
54
    // TODO Exceptiion if db_insert_id() is empty
55
    $dbId = $db->db_insert_id();
0 ignored issues
show
Bug introduced by
The method db_insert_id 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...
56
    $object->setDbId($dbId);
57
58
    return $dbId;
59
  }
60
61
}
62