ReflectionInstantiator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A instantiate() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Linio\Component\Input\Instantiator;
6
7
use Doctrine\Common\Inflector\Inflector;
8
9
class ReflectionInstantiator implements InstantiatorInterface
10
{
11
    public function instantiate(string $class, array $data)
12
    {
13
        $object = new $class();
14
        $reflection = new \ReflectionClass($object);
15
16
        foreach ($data as $key => $value) {
17
            $property = $reflection->getProperty(Inflector::camelize($key));
18
            if (!$property->isPublic()) {
19
                $property->setAccessible(true);
20
            }
21
22
            $property->setValue($object, $value);
23
        }
24
25
        return $object;
26
    }
27
}
28