| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | final class MappedHydrator implements Hydrates |
||
| 20 | { |
||
| 21 | private $class; |
||
| 22 | private $properties; |
||
| 23 | private $setter; |
||
| 24 | private $object; |
||
| 25 | |||
| 26 | private function __construct( |
||
| 27 | ReflectionClass $reflector, |
||
| 28 | MapsProperties $mapped, |
||
| 29 | Closure $setter = null |
||
| 30 | ) { |
||
| 31 | $this->class = $reflector; |
||
| 32 | $this->properties = $mapped; |
||
| 33 | $this->setter = $setter ?: function (string $attribute, $value) |
||
| 34 | { |
||
| 35 | $this->$attribute = $value; |
||
| 36 | }; |
||
| 37 | } |
||
| 38 | |||
| 39 | public static function forThe( |
||
| 46 | } |
||
| 47 | |||
| 48 | public function fromArray(array $data) |
||
| 49 | { |
||
| 50 | try { |
||
| 51 | $this->object = $this->class->newInstanceWithoutConstructor(); |
||
| 52 | $this->properties->writeData($this->object, $this->setter, $data); |
||
| 53 | return $this->object; |
||
| 54 | } catch (UnmappableInput $exception) { |
||
| 55 | throw CouldNotMap::encountered($exception, $this->class); |
||
| 56 | } finally { |
||
| 57 | $this->object = null; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | public function currentInstance() |
||
| 64 | } |
||
| 65 | } |
||
| 66 |