Total Complexity | 8 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class ClassMirror |
||
14 | { |
||
15 | /** @var PropertyAccessFactoryImpl */ |
||
16 | private $factory; |
||
17 | |||
18 | /** |
||
19 | */ |
||
20 | 7 | public function __construct() |
|
21 | { |
||
22 | 7 | $this->factory = new PropertyAccessFactoryImpl(); |
|
23 | 7 | } |
|
24 | |||
25 | /** |
||
26 | * @param mixed $subject |
||
27 | * |
||
28 | * @return PropertyAccess[] |
||
29 | */ |
||
30 | 7 | public function getAccessors($subject) |
|
31 | { |
||
32 | 7 | $class = self::ensureReflection($subject); |
|
33 | |||
34 | 7 | $result = []; |
|
35 | 7 | $current = $class; |
|
36 | |||
37 | 7 | while ($current) { |
|
38 | |||
39 | 7 | foreach ($current->getProperties() as $property) { |
|
40 | |||
41 | 7 | $propertyName = $property->getName(); |
|
42 | |||
43 | 7 | if (false === isset($result[$propertyName]) && false === $property->isStatic()) { |
|
44 | 7 | $result[$propertyName] = $this->factory->create($class, $property); |
|
45 | } |
||
46 | } |
||
47 | |||
48 | 7 | $current = $current->getParentClass(); |
|
49 | } |
||
50 | |||
51 | 7 | return $result; |
|
52 | } |
||
53 | |||
54 | 7 | private static function ensureReflection($subject) : \ReflectionClass |
|
57 | } |
||
58 | } |
||
59 |