| Total Complexity | 10 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 92% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | trait PropertyTrait |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @param $name |
||
| 9 | * |
||
| 10 | * @return mixed |
||
| 11 | */ |
||
| 12 | 21 | public function getProperty($name) |
|
| 13 | { |
||
| 14 | 21 | $methodName = 'get'.$this->strToStudlyCase($name); |
|
| 15 | 21 | if (method_exists($this, $methodName)) { |
|
| 16 | return $this->{$methodName}(); |
||
| 17 | } |
||
| 18 | |||
| 19 | 21 | if (array_key_exists($name, $this->properties)) { |
|
| 20 | 17 | return $this->properties[$name]; |
|
| 21 | } |
||
| 22 | |||
| 23 | 9 | if (array_key_exists($name, $this->readonlyProperties)) { |
|
| 24 | 8 | return $this->readonlyProperties[$name]; |
|
| 25 | } |
||
| 26 | 3 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param $name |
||
| 30 | * @param $value |
||
| 31 | */ |
||
| 32 | 19 | protected function setProperty($name, $value) |
|
| 33 | { |
||
| 34 | 19 | $methodName = 'set'.$this->strToStudlyCase($name); |
|
| 35 | 19 | if (method_exists($this, $methodName)) { |
|
| 36 | 18 | $this->{$methodName}($value); |
|
| 37 | |||
| 38 | 8 | return; |
|
| 39 | } |
||
| 40 | |||
| 41 | 4 | if (array_key_exists($name, $this->properties)) { |
|
| 42 | 4 | $this->properties[$name] = $value; |
|
| 43 | |||
| 44 | 4 | return; |
|
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 21 | public function __get($name) |
|
| 49 | { |
||
| 50 | 21 | return $this->getProperty($name); |
|
| 51 | } |
||
| 52 | |||
| 53 | 19 | public function __set($name, $value) |
|
| 56 | 9 | } |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param $key |
||
| 60 | * |
||
| 61 | * @return mixed |
||
| 62 | */ |
||
| 63 | 31 | protected function strToStudlyCase($key) |
|
| 68 |