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