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

ReflectionObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 51
ccs 0
cts 20
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A __debugInfo() 0 6 1
A __initialize() 0 4 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;
12
13
use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait;
14
use Go\ParserReflection\Traits\ReflectionClassLikeTrait;
15
use PhpParser\Node\Name;
16
use PhpParser\Node\Stmt\ClassLike;
17
use ReflectionObject as InternalReflectionObject;
18
19
/**
20
 * AST-based reflection for an object
21
 *
22
 * Typically, this class won't be used on parsing level, because if we have an instance of object,
23
 * then we can initialize a default ReflectionObject for it.
24
 */
25
class ReflectionObject extends InternalReflectionObject
26
{
27
    use ReflectionClassLikeTrait, InternalPropertiesEmulationTrait;
28
29
    /**
30
     * Instance of object
31
     *
32
     * @var object
33
     */
34
    private $instance;
35
36
    /**
37
     * Initializes reflection instance
38
     *
39
     * @param object $instance Instance of object
40
     * @param ClassLike $classLikeNode AST node for class definition
41
     */
42
    public function __construct($instance, ClassLike $classLikeNode = null)
43
    {
44
        $this->instance      = $instance;
45
        $fullClassName       = get_class($instance);
46
        $namespaceParts      = explode('\\', $fullClassName);
47
        $this->className     = array_pop($namespaceParts);
48
        // Let's unset original read-only property to have a control over it via __get
49
        unset($this->name);
50
51
        $this->namespaceName = join('\\', $namespaceParts);
52
53
        $this->classLikeNode = $classLikeNode ?: ReflectionEngine::parseClass($fullClassName);
54
    }
55
56
    /**
57
     * Emulating original behaviour of reflection
58
     */
59
    public function __debugInfo()
60
    {
61
        return array(
62
            'name' => $this->getName()
63
        );
64
    }
65
66
    /**
67
     * Implementation of internal reflection initialization
68
     *
69
     * @return void
70
     */
71
    protected function __initialize()
72
    {
73
        parent::__construct($this->instance);
74
    }
75
}
76