Completed
Push — master ( 934ce8...14a8a1 )
by Kirill
02:27
created

Properties::__debugInfo()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 27
rs 5.3846
cc 8
eloc 15
nc 8
nop 0
1
<?php
2
/**
3
 * This file is part of Properties package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 14.04.2016 17:07
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Serafim\Properties;
12
13
use Serafim\Properties\Support\Registry;
14
use Serafim\Properties\Support\Strings as Str;
15
16
/**
17
 * Class Properties
18
 * @package Serafim\Properties
19
 */
20
trait Properties
21
{
22
    use Getters, Setters;
23
24
25
26
27
    /**
28
     * @return array
29
     */
30
    public function __debugInfo()
31
    {
32
        $result = [];
33
        $reflection = new \ReflectionObject($this);
34
        $registry = Registry::get($this);
35
36
        foreach ($reflection->getProperties() as $property) {
37
            $name = $property->name;
38
            if ($property->isStatic()) {
39
                continue;
40
            }
41
42
            if ($property->isPublic()) {
43
                $result[$name] = $this->$name;
44
            }
45
46
            if ($property->isProtected() || $property->isPrivate()) {
47
                $property->setAccessible(true);
48
49
                if ($registry->has($name) && $registry->isReadable($name)) {
50
                    $result[$name] = $property->getValue($this);
51
                }
52
            }
53
        }
54
55
        return $result;
56
    }
57
}
58