DefaultPropertyCollector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B extract() 0 29 4
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
}