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

ReflectionNormalizer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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