Completed
Push — master ( e41e91...2b4213 )
by Aleh
01:47 queued 01:39
created

ClassData::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Padawan\Domain\Project\Node;
4
5
use Padawan\Domain\Project\FQCN;
6
use Padawan\Domain\Project\FQN;
7
use Padawan\Domain\Project\Collection\MethodsCollection;
8
use Padawan\Domain\Project\Collection\PropertiesCollection;
9
use Padawan\Domain\Project\Collection\ConstCollection;
10
11
/**
12
 * @property $properties
13
 * @property $methods
14
 * @property $constants
15
 */
16
class ClassData
17
{
18
    const MODIFIER_PUBLIC    = 1;
19
    const MODIFIER_PROTECTED = 2;
20
    const MODIFIER_PRIVATE   = 4;
21
    const MODIFIER_STATIC    = 8;
22
    const MODIFIER_ABSTRACT  = 16;
23
    const MODIFIER_FINAL     = 32;
24
    public $interfaces = [];
25
    /** @var Uses */
26
    public $uses;
27
28
    /**
29
     * @var FQCN
30
     */
31
    public $fqcn;
32
    public $doc             = "";
33
    public $startLine       = 0;
34
    public $file            = "";
35
    public function __construct(FQCN $fqcn, $file)
36
    {
37
        $this->fqcn = $fqcn;
38
        $this->file = $file;
39
        $this->constants = new ConstCollection($this);
40
        $this->methods = new MethodsCollection($this);
41
        $this->properties = new PropertiesCollection($this);
42
    }
43
44
    /**
45
     * @return ClassData
46
     */
47
    public function getParent()
48
    {
49
        return $this->parent;
50
    }
51
52
    /**
53
     * @return InterfaceData[]
54
     */
55
    public function getInterfaces()
56
    {
57
        return $this->interfaces;
58
    }
59
60
    public function getName()
61
    {
62
        return $this->fqcn->getClassName();
63
    }
64
    public function setParent($parent)
65
    {
66
        if ($this === $parent) {
67
            throw new \Exception("Parent class and child class could not be same");
68
        }
69
        $this->parent = null;
70
        if ($parent instanceof ClassData) {
71
            foreach ($this->methods->all() as $method) {
72
                if ($method->doc === Comment::INHERIT_MARK) {
73
                    $parentMethod = $parent->methods->get($method->name);
74
                    if ($parentMethod instanceof MethodData) {
75
                        $method->doc = $parentMethod->doc;
76
                        $method->setReturn($parentMethod->getReturn());
77
                    }
78
                }
79
            }
80
        }
81
        $this->parent = $parent;
82
    }
83
    public function addInterface($interface)
84
    {
85
        $fqcn = $interface instanceof InterfaceData ? $interface->fqcn : $interface;
86
        $this->interfaces[$fqcn->toString()] = $interface;
87
    }
88
    public function addMethod(MethodData $method)
89
    {
90
        $this->methods->add($method);
91
    }
92
    public function getMethod($methodName)
93
    {
94
        return $this->methods->get($methodName);
95
    }
96
    public function hasMethod($methodName)
97
    {
98
        return $this->methods->get($methodName) !== null;
99
    }
100
    public function getProp($propName)
101
    {
102
        return $this->properties->get($propName);
103
    }
104
    public function hasProp($propName)
105
    {
106
        return $this->properties->get($propName) !== null;
107
    }
108
    public function addProp(ClassProperty $prop)
109
    {
110
        $this->properties->add($prop);
111
    }
112
    public function addConst($constName)
113
    {
114
        $this->constants->add($constName);
115
    }
116
    public function __get($name)
117
    {
118
        if ($name === 'methods') {
119
            return $this->methods;
120
        } elseif ($name === 'properties') {
121
            return $this->properties;
122
        } elseif ($name === 'constants') {
123
            return $this->constants;
124
        }
125
    }
126
127
    /** @var ClassData */
128
    private $parent;
129
    /** @var MethodsCollection */
130
    private $methods;
131
    /** @var PropertiesCollection */
132
    private $properties;
133
    /** @var ConstCollection */
134
    private $constants;
135
}
136