Completed
Push — master ( 3647eb...c1bd1c )
by Tomasz
06:27
created

ReflectionNormalizer::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4286
cc 3
eloc 9
nc 3
nop 1
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
    public function __construct(array $skipped = [])
12
    {
13
        $this->skipped = $skipped;
14
    }
15
16
    public function __invoke($var)
17
    {
18
        $ref = new \ReflectionObject($var);
19
20
        $result = [];
21
        foreach($ref->getProperties() as $property) {
22
            if(in_array($property->getName(), $this->skipped)) {
23
                continue;
24
            }
25
26
            $property->setAccessible(true);
27
28
            $result[$property->getName()] = $property->getValue($var);
29
        }
30
31
        return $result;
32
    }
33
}
34