Test Failed
Branch trunk (412648)
by SuperNova.WS
03:40
created

ActiveRecord::find()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 12.06.2017 14:41
4
 */
5
6
namespace DBAL;
7
8
/**
9
 * Class ActiveRecord
10
 *
11
 * Represent table in DB/one record in DB. Breaking SRP with joy!
12
 *
13
 * @property int|string $id - Record ID name would be normalized to 'id'
14
 *
15
 * @package DBAL
16
 */
17
abstract class ActiveRecord extends ActiveRecordAbstract {
18
19
  /**
20
   * @inheritdoc
21
   */
22
  protected function dbInsert() {
23
    return
24
      static::dbPrepareQuery()
25
        ->setValues(static::translateNames($this->values, self::PROPERTIES_TO_FIELDS))
26
        ->doInsert();
27
  }
28
29
  /**
30
   * @inheritdoc
31
   */
32
  protected function dbLastInsertId() {
33
    return static::db()->db_insert_id();
34
  }
35
36
  /**
37
   * @inheritdoc
38
   */
39
  protected function dbUpdate() {
40
    return
41
      static::dbPrepareQuery()
42
        ->setValues(empty($this->_changes) ? [] : static::translateNames($this->_changes, self::PROPERTIES_TO_FIELDS))
43
        ->setAdjust(empty($this->_deltas) ? [] : static::translateNames($this->_deltas, self::PROPERTIES_TO_FIELDS))
44
        ->setWhereArray([static::$_primaryIndexField => $this->id])
45
        ->doUpdate();
46
  }
47
48
}
49