| Total Complexity | 12 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 4 | class VisibilityOverride { |
||
| 5 | private $readClosure; |
||
| 6 | private $writeClosure; |
||
| 7 | |||
| 8 | public function __construct($object) { |
||
| 9 | if ($object instanceof \stdclass) { |
||
| 10 | $this->readClosure = function() use ($object) { return $object; }; |
||
| 11 | $this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; }; |
||
| 12 | } |
||
| 13 | else { |
||
| 14 | $this->readClosure = function() { |
||
| 15 | $data = new \stdClass; |
||
| 16 | foreach ($this as $k => $v) { |
||
| 17 | if (is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTime)) $data->$k = $v; |
||
| 18 | } |
||
| 19 | return $data; |
||
| 20 | }; |
||
| 21 | $this->readClosure = $this->readClosure->bindTo($object, $object); |
||
| 22 | |||
| 23 | $this->writeClosure = function ($field, $value) { $this->$field = $value; }; |
||
| 24 | $this->writeClosure = $this->writeClosure->bindTo($object, $object); |
||
| 25 | } |
||
| 26 | |||
| 27 | } |
||
| 28 | |||
| 29 | public function getProperties() { |
||
| 30 | return ($this->readClosure)(); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function write($data) { |
||
| 34 | if ($data != null) { |
||
| 35 | foreach ($data as $key => $value) { |
||
| 36 | ($this->writeClosure)($key, $this->processDates($value)); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | private function processDates($obj) { |
||
| 44 | } |
||
| 45 | } |