| Conditions | 3 |
| Paths | 2 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 19 | 10 | public static function fromNative($state): self |
|
| 20 | { |
||
| 21 | 10 | Assert::that($state)->nullOr()->isTraversable( |
|
| 22 | 10 | 'State provided to '.static::class.' must be null or iterable' |
|
| 23 | ); |
||
| 24 | |||
| 25 | 10 | $entities = []; |
|
| 26 | 10 | $typeFactories = static::getTypeFactories(); |
|
| 27 | 10 | if (!is_null($state)) { |
|
| 28 | 10 | foreach ($state as $data) { |
|
| 29 | 10 | Assert::that($data)->keyExists(EntityInterface::TYPE_KEY, 'Entity state is missing type key.'); |
|
| 30 | 10 | $entityType = $data[EntityInterface::TYPE_KEY]; |
|
| 31 | 10 | $entities[] = call_user_func($typeFactories[$entityType], $data); |
|
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | 10 | return new static($entities); |
|
| 36 | } |
||
| 53 |