Completed
Push — master ( c5deb5...290f06 )
by Karsten
02:50
created

ClassMirror::getAccessorsToAllNonStaticProperties()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 20
ccs 0
cts 15
cp 0
rs 8.8571
c 1
b 0
f 1
cc 5
eloc 10
nc 4
nop 0
crap 30
1
<?php
2
/**
3
 * Created by gerk on 24.11.16 22:37
4
 */
5
6
namespace PeekAndPoke\Component\PropertyAccess;
7
8
/**
9
 * ClassMirror
10
 *
11
 * @author Karsten J. Gerber <[email protected]>
12
 */
13
class ClassMirror
14
{
15
    /** @var PropertyAccessFactoryImpl */
16
    private $factory;
17
18
    /**
19
     */
20
    public function __construct()
21
    {
22
        $this->factory = new PropertyAccessFactoryImpl();
23
    }
24
25
    /**
26
     * @param mixed $subject
27
     *
28
     * @return PropertyAccess[]
29
     */
30
    public function getAccessors($subject)
31
    {
32
        $class = $subject instanceof \ReflectionClass ? $subject : new \ReflectionClass($subject);
33
34
        $result  = [];
35
        $current = $class;
36
37
        while ($current) {
38
39
            foreach ($current->getProperties() as $property) {
40
41
                $propertyName = $property->getName();
42
43
                if (false === isset($result[$propertyName]) && false === $property->isStatic()) {
44
                    $result[$propertyName] = $this->factory->create($class, $property);
45
                }
46
            }
47
            $current = $current->getParentClass();
48
        }
49
50
        return $result;
51
    }
52
}
53