Completed
Push — master ( 839f22...1b3a7e )
by Pavel
04:14
created

ReflectionConstructorFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createEntity() 0 6 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds;
4
5
final class ReflectionConstructorFactory implements EntityFactoryInterface
6
{
7
    /** @var  string */
8
    private $className;
9
    /** @var  array */
10
    private $args = [];
11
12
    /**
13
     * ReflectionConstructorFactory constructor.
14
     *
15
     * @param string $className
16
     * @param array  $args
17
     */
18 4
    public function __construct($className, array $args = [])
19
    {
20 4
        $this->className = $className;
21 4
        $this->args      = $args;
22 4
    }
23
24
    /** {@inheritdoc} */
25 4
    public function createEntity($data)
26
    {
27 4
        $reflection = new \ReflectionClass($this->className);
28
29 4
        return $reflection->newInstanceArgs($this->args);
30
    }
31
}
32