ReflectionNormalizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 21 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