Conditions | 2 |
Paths | 2 |
Total Lines | 32 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
32 | 1 | public function createFromArray(array $array): Entity |
|
33 | { |
||
34 | /** |
||
35 | * @var Entity $entity |
||
36 | */ |
||
37 | 1 | $reflector = new \ReflectionClass($this->entityClass); |
|
38 | |||
39 | 1 | $entity = $reflector->newInstanceWithoutConstructor(); |
|
40 | |||
41 | 1 | $columns = $entity::getColumns(); |
|
42 | 1 | unset($columns['id'], $columns['modified'], $columns['created']); |
|
43 | |||
44 | 1 | $arguments = []; |
|
45 | |||
46 | 1 | foreach ($columns as $column => $type) { |
|
47 | 1 | $property = new EntityProperty($type); |
|
48 | |||
49 | 1 | $arguments[$column] = $property->formatValueForEntity($array[$column]); |
|
50 | } |
||
51 | |||
52 | 1 | $entity = $reflector->newInstanceArgs($arguments); |
|
53 | 1 | $entity->set('id', $array['id']); |
|
54 | 1 | $entity->set('modified', new \DateTime($array['modified'])); |
|
55 | 1 | $entity->set('created', new \DateTime($array['created'])); |
|
56 | |||
57 | /** |
||
58 | * Mark entity as unaltered |
||
59 | */ |
||
60 | 1 | $entity->setUnaltered(); |
|
61 | |||
62 | 1 | return $entity; |
|
63 | } |
||
64 | } |
||
65 |