| Total Complexity | 11 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class GenericEntityHydrator implements HydratorInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Orm |
||
| 14 | */ |
||
| 15 | protected $orm; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var Mapper |
||
| 19 | */ |
||
| 20 | protected $mapper; |
||
| 21 | |||
| 22 | public function __construct(Orm $orm, Mapper $mapper) |
||
| 23 | { |
||
| 24 | $this->orm = $orm; |
||
| 25 | $this->mapper = $mapper; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function hydrate($attributes = []) |
||
| 29 | { |
||
| 30 | $attributes = $this->mapColumnsToAttributes($attributes); |
||
| 31 | $class = $this->mapper->getEntityClass() ?? GenericEntity::class; |
||
| 32 | |||
| 33 | return new $class($attributes, $this->orm->getCastingManager()); |
||
| 34 | } |
||
| 35 | |||
| 36 | protected function mapColumnsToAttributes($arr) |
||
| 51 | } |
||
| 52 | |||
| 53 | public function extract(EntityInterface $entity) |
||
| 54 | { |
||
| 55 | $data = $this->mapAttributesToColumns($entity->getArrayCopy()); |
||
| 56 | |||
| 57 | return Arr::only($data, $this->mapper->getColumns()); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function mapAttributesToColumns($arr) |
||
| 75 | } |
||
| 76 | } |
||
| 77 |