EntityFactory::createEntity()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace SpareParts\Pillar\Entity;
3
4
use SpareParts\Pillar\Assistant\Dibi\IEntityFactory;
5
use SpareParts\Pillar\Mapper\IMapper;
6
7
class EntityFactory implements IEntityFactory
8
{
9
	/**
10
	 * @param string $entityClassName
11
	 * @param mixed[] $data
12
	 * @return IEntity
13
	 */
14
	public function createEntity($entityClassName, array $data)
15
	{
16
		// Try to fix strange Dibi datetime behaviour by using standard (and immutable!) datetime class
17 1
		$data = array_map(function($column) {
18 1
			return ($column instanceof \DateTime) ? \DateTimeImmutable::createFromMutable($column) : $column;
19 1
		}, $data);
20
21 1
		return new $entityClassName($data);
22
	}
23
}
24