EntityFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A create() 0 4 1
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