Completed
Push — master ( 6c5557...d84e1e )
by Alexander
03:46
created

InternalPropertiesEmulationTrait::__debugInfo()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
/**
3
 * Parser Reflection API
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\ParserReflection\Traits;
12
13
/**
14
 * Class for emulating internal properties behaviour
15
 */
16
trait InternalPropertiesEmulationTrait
17
{
18
    /**
19
     * Magic method that should be defined to provide an info about internal properties
20
     *
21
     * @return array
22
     */
23
    abstract public function __debugInfo();
24
25
    /**
26
     * Magic implementation of properties
27
     *
28
     * @param string $propertyName Name of the property to return
29
     *
30
     * @return null|mixed
31
     */
32
    public function __get($propertyName)
33
    {
34
        $internalInfo = $this->__debugInfo();
35
        if (!isset($internalInfo[$propertyName])) {
36
            $className = get_class($this);
37
            trigger_error("Undefined property {$className}::\${$propertyName}");
38
39
            return null;
40
        }
41
42
        return $internalInfo[$propertyName];
43
    }
44
}
45