Test Failed
Push — trunk ( 0d5d14...30e273 )
by SuperNova.WS
11:46
created

AccessLogged::isChanged()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 16.06.2017 14:32
4
 */
5
6
namespace Common;
7
8
9
use Exception;
10
11
/**
12
 * Class AccessLogged
13
 *
14
 * Logs property changes. It's necessary for delta and/or partial DB updates
15
 *
16
 * On first property change it goes to start values
17
 *
18
 * @package Common
19
 * @deprecated
20
 */
21
// TODO - Should be replaced with AccessLoggedV2
22
class AccessLogged extends AccessLoggedAbstract {
23
24
  public function __set($name, $value) {
25
    if ($this->_currentOperation === self::ACCESS_SET) {
26
      $this->valueSet($name, $value);
27
    } else {
28
      $this->valueDelta($name, $value);
29
    }
30
  }
31
32
  /**
33
   * @param string $name
34
   * @param $value
35
   *
36
   * @throws Exception
37
   */
38
  protected function valueSet($name, $value) {
39
    if ($this->__isset($name)) {
40
      $this->blockChange($name);
41
42
      $this->_changes[$name] = $value;
43
    } else {
44
      $this->_startValues[$name] = $value;
45
    }
46
47
    parent::__set($name, $value);
48
  }
49
50
  /**
51 2
   * @param string $name
52 2
   * @param mixed $value
53 2
   *
54 2
   * @throws Exception
55 2
   */
56
  protected function valueDelta($name, $value) {
57 2
    $this->blockDelta($name);
58
59 1
    !isset($this->_deltas[$name]) ? $this->_deltas[$name] = 0 : false;
60 1
    !isset($this->_startValues[$name]) ? $this->_startValues[$name] = 0 : false;
61 1
62 1
    $value *= $this->_currentOperation === self::ACCESS_DELTA_DEC ? -1 : +1;
63
64
    $this->_deltas[$name] += $value;
65
66
    parent::__set($name, parent::__get($name) + $value);
67
68
    $this->_currentOperation = self::ACCESS_SET;
69 1
  }
70 1
71
}
72