| Total Complexity | 8 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 10 | final class RelationCollectionMapping implements Mapping |
||
| 11 | { |
||
| 12 | /** @var string */ |
||
| 13 | private $name; |
||
| 14 | /** @var Deserializer */ |
||
| 15 | private $collection; |
||
| 16 | /** @var Deserializer */ |
||
| 17 | private $item; |
||
| 18 | |||
| 19 | private function __construct( |
||
| 20 | string $name, |
||
| 21 | Deserializer $collection, |
||
| 22 | Deserializer $item |
||
| 23 | ) { |
||
| 24 | $this->name = $name; |
||
| 25 | $this->collection = $collection; |
||
| 26 | $this->item = $item; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function inProperty( |
||
| 30 | string $name, |
||
| 31 | Deserializer $collection, |
||
| 32 | Deserializer $item |
||
| 33 | ): Mapping { |
||
| 34 | return new self($name, $collection, $item); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function name(): string |
||
| 38 | { |
||
| 39 | return $this->name; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function value(array $data, $owner = null) |
||
| 43 | { |
||
| 44 | try { |
||
| 45 | $objects = $this->itemsFromArray($data); |
||
| 46 | } catch (Throwable $exception) { |
||
| 47 | throw RelationMappingFailure::encountered($this, $exception); |
||
| 48 | } |
||
| 49 | try { |
||
| 50 | return $this->collection->from($objects); |
||
| 51 | } catch (Throwable $exception) { |
||
| 52 | throw CollectionMappingFailure::encountered($this, $exception); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param array[] $data |
||
| 58 | * @return object[] |
||
| 59 | * @throws DeserializationFailure |
||
| 60 | */ |
||
| 61 | private function itemsFromArray(array $data): array |
||
| 68 | } |
||
| 69 | } |
||
| 70 |