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

ReflectionConstructorFactory::createEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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