ReflectionConstructorFactory::createEntity()   A
last analyzed

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 10
    public function __construct($className, array $args = [])
19
    {
20 10
        $this->className = $className;
21 10
        $this->args      = $args;
22 10
    }
23
24
    /** {@inheritdoc} */
25 10
    public function createEntity($data)
26
    {
27 10
        $reflection = new \ReflectionClass($this->className);
28
29 10
        return $reflection->newInstanceArgs($this->args);
30
    }
31
}
32