1 | <?php |
||
13 | abstract class ModelA extends Base implements ModelInterface { |
||
14 | use ArrayAccessTrait; |
||
15 | use CountableTrait; |
||
16 | use IteratorTrait; |
||
17 | |||
18 | /** |
||
19 | * @param string $sIncName |
||
20 | * @return mixed |
||
21 | */ |
||
22 | 2 | public function __get($sIncName) { |
|
23 | try { |
||
24 | 2 | $oProperty = new \ReflectionProperty($this, $sIncName); |
|
25 | 2 | if (!$oProperty->isPublic()) { |
|
26 | // try for a getter method |
||
27 | 1 | $sGetterName = 'get' . ucfirst($sIncName); |
|
28 | 1 | $oGetter = new \ReflectionMethod($this, $sGetterName); |
|
|
|||
29 | |||
30 | $this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way |
||
31 | return $oGetter->invoke($this, $sIncName); |
||
32 | } else { |
||
33 | 1 | $this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way |
|
34 | 1 | return $oProperty->getValue($this); |
|
35 | } |
||
36 | 1 | } catch (\ReflectionException $e) { |
|
37 | // reflection issue |
||
38 | 1 | return parent::__get($sIncName); |
|
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $sIncName |
||
44 | * @param mixed $value |
||
45 | * @throws ExceptionUnimplemented |
||
46 | * @throws \ReflectionException |
||
47 | */ |
||
48 | 1 | public function __set($sIncName, $value) { |
|
49 | 1 | if (is_null($sIncName)) { |
|
50 | throw new \ReflectionException('Can\'t set a value to a null property on the current object [' . get_class($this) . ']'); |
||
51 | } |
||
52 | try { |
||
53 | 1 | $oProperty = new \ReflectionProperty($this, $sIncName); |
|
54 | 1 | if (!$oProperty->isPublic()) { |
|
55 | // trying for a setter |
||
56 | $sSetterName = 'set' . ucfirst($sIncName); |
||
57 | $oSetter = new \ReflectionMethod($this, $sSetterName); |
||
58 | |||
59 | $oSetter->invoke($this, $value); |
||
60 | } else { |
||
61 | 1 | $oProperty->setValue($this, $value); |
|
62 | } |
||
63 | |||
64 | 1 | $this->_current = $sIncName; |
|
65 | 1 | return; |
|
66 | } catch (\ReflectionException $e) { |
||
67 | // $this->_current = $sIncName; |
||
68 | // $this->$sIncName = $value; |
||
69 | } |
||
70 | |||
71 | parent::__set($sIncName, $value); |
||
72 | } |
||
73 | |||
74 | 10 | public function __construct() { |
|
77 | |||
78 | /** |
||
79 | * @param bool $bAll |
||
80 | * @return array |
||
81 | */ |
||
82 | 11 | protected function getPropertyNames($bAll = false) { |
|
97 | |||
98 | /** |
||
99 | * @param bool $bIncludeProtected |
||
100 | * @return array |
||
101 | */ |
||
102 | 2 | protected function getProperties($bIncludeProtected = false) { |
|
119 | |||
120 | /** |
||
121 | * recursively transform all properties into arrays |
||
122 | */ |
||
123 | 1 | public function toArray() { |
|
141 | } |
||
142 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.