Completed
Push — work-fleets ( 04acf9...8f8df9 )
by SuperNova.WS
07:02
created

DbRowDirectOperator::insert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.4285
ccs 0
cts 9
cp 0
crap 6
1
<?php
2
3
/**
4
 * Class DbRowDirectOperator
5
 *
6
 * Handle Entity storing/loading operations
7
 */
8
9
class DbRowDirectOperator implements \Common\IEntityOperator {
10
11
  /**
12
   * @param \Common\IEntity $entity
13
   *
14
   * @return array
15
   */
16
  public function getById($entity) {
17
    $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...
18
      ->setIdField($entity->getIdFieldName())
19
      ->field('*')
20
      ->from($entity->getTableName())
21
      ->where($entity->getIdFieldName() . ' = "' . $entity->dbId . '"');
0 ignored issues
show
Bug introduced by
Accessing dbId on the interface Common\IEntity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
22
23
    return $stmt->selectRow();
24
  }
25
26
  /**
27
   * @param \Common\IEntity $entity
28
   */
29
  public function deleteById($entity) {
30
    $db = $entity->getDbStatic();
31
32
    $db->doDeleteRowWhere($entity->getTableName(), array($entity->getIdFieldName() => $entity->dbId));
0 ignored issues
show
Bug introduced by
Accessing dbId on the interface Common\IEntity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
33
34
    return $db->db_affected_rows();
35
  }
36
37
  /**
38
   * @param \Common\IEntity $entity
39
   */
40
  public function insert($entity) {
41
    $db = $entity->getDbStatic();
42
43
    $row = $entity->exportRowWithoutId();
44
    if (empty($row)) {
45
      // TODO Exceptiion
46
      return 0;
47
    }
48
    $db->doInsertSet($entity->getTableName(), $row);
49
50
    // TODO Exceptiion if db_insert_id() is empty
51
    return $entity->dbId = $db->db_insert_id();
0 ignored issues
show
Bug introduced by
Accessing dbId on the interface Common\IEntity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
52
  }
53
54
}
55