DefaultPropertyCollector::extract()   B
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.5806
c 0
b 0
f 0
nc 5
cc 4
eloc 21
nop 1
1
<?php
2
3
namespace Magium\Util\Configuration\ConfigurationCollector;
4
5
use Magium\AbstractConfigurableElement;
6
7
class DefaultPropertyCollector
8
{
9
10
    /**
11
     * @param AbstractConfigurableElement|string $element
12
     * @return Property[]
13
     */
14
15
    public function extract(
16
        $element
17
    )
18
    {
19
        $return = [];
20
        $reflection = new \ReflectionClass($element);
21
        $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
22
        $defaultValues = $reflection->getDefaultProperties();
23
        foreach ($properties as $property) {
24
            $value = '<empty>';
25
            if (isset($defaultValues[$property->getName()])) {
26
                $value = $defaultValues[$property->getName()];
27
            }
28
            if ($property->getDocComment()) {
29
                $option = new Property(
30
                    $property->getName(),
31
                    $value,
32
                    $property->getDocComment()
33
                );
34
            } else {
35
                $option = new Property(
36
                    $property->getName(),
37
                    $value
38
                );
39
            }
40
            $return[] = $option;
41
        }
42
        return $return;
43
    }
44
45
}