1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHP Mess Detector. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Manuel Pichler <[email protected]>. |
6
|
|
|
* All rights reserved. |
7
|
|
|
* |
8
|
|
|
* Licensed under BSD License |
9
|
|
|
* For full copyright and license information, please see the LICENSE file. |
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
11
|
|
|
* |
12
|
|
|
* @author Manuel Pichler <[email protected]> |
13
|
|
|
* @copyright Manuel Pichler. All rights reserved. |
14
|
|
|
* @license https://opensource.org/licenses/bsd-license.php BSD License |
15
|
|
|
* @link http://phpmd.org/ |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace PHPMD\Node; |
19
|
|
|
|
20
|
|
|
use PDepend\Source\AST\AbstractASTClassOrInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Abstract base class for classes and interfaces. |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractTypeNode extends AbstractNode |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \PDepend\Source\AST\AbstractASTClassOrInterface |
29
|
|
|
*/ |
30
|
|
|
private $node; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructs a new generic class or interface node. |
34
|
|
|
* |
35
|
|
|
* @param \PDepend\Source\AST\AbstractASTClassOrInterface $node |
36
|
|
|
*/ |
37
|
20 |
|
public function __construct(AbstractASTClassOrInterface $node) |
38
|
|
|
{ |
39
|
20 |
|
parent::__construct($node); |
40
|
|
|
|
41
|
20 |
|
$this->node = $node; |
42
|
20 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns an <b>array</b> with all methods defined in the context class or |
46
|
|
|
* interface. |
47
|
|
|
* |
48
|
|
|
* @return \PHPMD\Node\MethodNode[] |
49
|
|
|
*/ |
50
|
7 |
|
public function getMethods() |
51
|
|
|
{ |
52
|
7 |
|
$methods = array(); |
53
|
7 |
|
foreach ($this->node->getMethods() as $method) { |
54
|
7 |
|
$methods[] = new MethodNode($method); |
55
|
|
|
} |
56
|
7 |
|
|
57
|
|
|
return $methods; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns an array with the names of all methods within this class or |
62
|
|
|
* interface node. |
63
|
|
|
* |
64
|
|
|
* @return string[] |
65
|
3 |
|
*/ |
66
|
|
|
public function getMethodNames() |
67
|
3 |
|
{ |
68
|
3 |
|
$names = array(); |
69
|
3 |
|
foreach ($this->node->getMethods() as $method) { |
70
|
|
|
$names[] = $method->getName(); |
71
|
3 |
|
} |
72
|
|
|
|
73
|
|
|
return $names; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the number of constants declared in this type. |
78
|
|
|
* |
79
|
5 |
|
* @return integer |
80
|
|
|
*/ |
81
|
5 |
|
public function getConstantCount() |
82
|
|
|
{ |
83
|
|
|
return count($this->node->getConstants()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the name of the parent namespace. |
88
|
|
|
* |
89
|
3 |
|
* @return string |
90
|
|
|
*/ |
91
|
3 |
|
public function getNamespaceName() |
92
|
|
|
{ |
93
|
|
|
return $this->node->getNamespace()->getName(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the name of the parent type or <b>null</b> when this node has no |
98
|
|
|
* parent type. |
99
|
|
|
* |
100
|
3 |
|
* @return string |
101
|
|
|
*/ |
102
|
3 |
|
public function getParentName() |
103
|
|
|
{ |
104
|
|
|
return null; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the full qualified name of a class, an interface, a method or |
109
|
|
|
* a function. |
110
|
|
|
* |
111
|
3 |
|
* @return string |
112
|
|
|
*/ |
113
|
3 |
|
public function getFullQualifiedName() |
114
|
|
|
{ |
115
|
|
|
return sprintf('%s\\%s', $this->getNamespaceName(), $this->getName()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|