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