| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | final class ObjectHydrator implements Hydrates |
||
| 21 | { |
||
| 22 | private $setter; |
||
| 23 | |||
| 24 | private function __construct( |
||
| 25 | ?Closure $setter |
||
| 26 | ) { |
||
| 27 | $this->setter = $setter ?: function (string $attribute, $value): void { |
||
| 28 | $this->$attribute = $value; |
||
| 29 | }; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Produces an object hydrator with a default setter. |
||
| 34 | * |
||
| 35 | * @return Hydrates A hydrator that uses closure binding to write properties. |
||
| 36 | */ |
||
| 37 | public static function default(): Hydrates |
||
| 38 | { |
||
| 39 | return new self(null); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Produces an object hydrator with a custom setter. |
||
| 44 | * |
||
| 45 | * @param Closure $setter The closure that writes the values. |
||
| 46 | * @return Hydrates A hydrator that uses a custom closure to write |
||
| 47 | * properties. |
||
| 48 | */ |
||
| 49 | public static function using( |
||
| 53 | } |
||
| 54 | |||
| 55 | /** @inheritdoc */ |
||
| 56 | public function writeTo(object $target, array $data): void |
||
| 63 | } |
||
| 64 | } |
||
| 67 |