EntityFactory::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
namespace Ajir\RabbitMqSqlBundle\Factory;
3
4
use InvalidArgumentException;
5
use ReflectionClass;
6
7
/**
8
 * Class EntityFactory
9
 *
10
 * @author Florian Ajir <[email protected]>
11
 */
12
class EntityFactory implements EntityFactoryInterface
13
{
14
    const MODEL_INTERFACE = 'Ajir\RabbitMqSqlBundle\Model\EntityInterface';
15
16
    /**
17
     * @var ReflectionClass
18
     */
19
    protected $class;
20
21
    /**
22
     * @var RelationFactoryInterface
23
     */
24
    protected $relationFactory;
25
26
    /**
27
     * @param string $classname
28
     *
29
     * @throws InvalidArgumentException
30
     */
31 4
    public function __construct($classname)
32
    {
33 4
        $this->class = new ReflectionClass($classname);
34 4
        if (!$this->class->implementsInterface(self::MODEL_INTERFACE)) {
35 1
            throw new InvalidArgumentException();
36
        }
37 3
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 2
    public function create(array $data)
43
    {
44 2
        return $this->class->newInstance($data);
45
    }
46
}
47