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

DbRowDirectOperator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 46
rs 10
ccs 0
cts 22
cp 0
wmc 4
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getById() 0 9 1
A deleteById() 0 7 1
A insert() 0 13 2
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