| Conditions | 7 |
| Paths | 2 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | } |
||
| 45 | } |