ReflectionPropertySetFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 4
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Internal\Data;
10
11
use ReflectionClass;
12
use ReflectionProperty;
13
14
/**
15
 * Class ReflectionPropertySetFactory
16
 *
17
 * Create a set of reflection properties, preferring properties of child classes
18
 * over parent classes.
19
 *
20
 * @author Nate Brunette <[email protected]>
21
 */
22
final class ReflectionPropertySetFactory
23
{
24
    /**
25
     * Get a flat list of all properties in class and parent classes
26
     *
27
     * @param ReflectionClass $reflectionClass
28
     * @return ReflectionPropertySet
29
     */
30 5
    public function create(ReflectionClass $reflectionClass): ReflectionPropertySet
31
    {
32 5
        $properties = new ReflectionPropertySet();
33 5
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
34 4
            $properties->add($reflectionProperty);
35
        }
36
37 5
        $parentClass = $reflectionClass->getParentClass();
38
39 5
        while (false !== $parentClass) {
40
            // add all private properties from parent
41 4
            foreach ($parentClass->getProperties(ReflectionProperty::IS_PRIVATE) as $property) {
42 1
                $properties->add($property);
43
            }
44
45
            // reset $parentClass
46 4
            $parentClass = $parentClass->getParentClass();
47
        }
48
49 5
        return $properties;
50
    }
51
}
52