ReflectionNormalizer::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 9.584
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php
2
namespace Thunder\Serializard\Normalizer;
3
4
/**
5
 * @author Tomasz Kowalczyk <[email protected]>
6
 */
7
final class ReflectionNormalizer
8
{
9
    private $skipped;
10
11 12
    public function __construct(array $skipped = [])
12
    {
13 12
        $this->skipped = $skipped;
14 12
    }
15
16 9
    public function __invoke($var)
17
    {
18 9
        $ref = new \ReflectionObject($var);
19
20 9
        $result = [];
21 9
        while($ref) {
22 9
            foreach($ref->getProperties() as $property) {
23 9
                if(\in_array($property->getName(), $this->skipped, true)) {
24 3
                    continue;
25
                }
26
27 9
                $property->setAccessible(true);
28
29 9
                $result[$property->getName()] = $property->getValue($var);
30
            }
31
32 9
            $ref = $ref->getParentClass();
33
        }
34
35 9
        return $result;
36
    }
37
}
38