Completed
Pull Request — master (#2)
by Tomasz
01:59
created

ReflectionHydrator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
1
<?php
2
namespace Thunder\Serializard\Hydrator;
3
4
use Thunder\Serializard\HydratorContainer\HydratorContainerInterface;
5
6
final class ReflectionHydrator
7
{
8
    public function __invoke(array $data, HydratorContainerInterface $hydrators)
9
    {
10
        // FIXME: Refactor hydration to allow generic hydrators
11
        $ref = new \ReflectionClass($class);
0 ignored issues
show
Bug introduced by
The variable $class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
12
        $object = $ref->newInstanceWithoutConstructor();
0 ignored issues
show
Bug introduced by
The method newInstanceWithoutConstructor() does not exist on ReflectionClass. Did you maybe mean newInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
13
14
        foreach($ref->getProperties() as $property) {
15
            $property->setAccessible(true);
16
            $property->setValue($object, $data[$property->getName()]);
17
        }
18
19
        return $object;
20
    }
21
}
22