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

ReflectionNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 27
rs 10

2 Methods

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