|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Project\Node; |
|
4
|
|
|
|
|
5
|
|
|
use Padawan\Domain\Project\FQCN; |
|
6
|
|
|
use Padawan\Domain\Project\Node\ClassProperty; |
|
7
|
|
|
use Padawan\Domain\Project\Node\Variable; |
|
8
|
|
|
|
|
9
|
|
|
class Comment { |
|
10
|
|
|
const INHERIT_MARK = 'inheritdoc'; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct($doc) { |
|
13
|
|
|
$this->doc = $doc; |
|
14
|
|
|
} |
|
15
|
|
|
public function addVar(Variable $var) { |
|
16
|
|
|
$this->vars[$var->getName()] = $var; |
|
17
|
|
|
} |
|
18
|
|
|
public function addProperty(ClassProperty $prop) { |
|
19
|
|
|
$this->properties[$prop->name] = $prop; |
|
20
|
|
|
} |
|
21
|
|
|
public function getVars() { |
|
22
|
|
|
return $this->vars; |
|
23
|
|
|
} |
|
24
|
|
|
public function getProperties() { |
|
25
|
|
|
return $this->properties; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return ClassProperty |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getProperty($name) { |
|
32
|
|
|
$prop = null; |
|
33
|
|
|
if (array_key_exists($name, $this->properties)) { |
|
34
|
|
|
$prop = $this->properties[$name]; |
|
35
|
|
|
} |
|
36
|
|
|
if (!$prop instanceof ClassProperty && array_key_exists('', $this->properties)) { |
|
37
|
|
|
$prop = $this->properties['']; |
|
38
|
|
|
} |
|
39
|
|
|
if (empty($prop)) { |
|
40
|
|
|
$var = $this->getVar($name); |
|
41
|
|
|
if ($var instanceof Variable) { |
|
42
|
|
|
$prop = new ClassProperty; |
|
43
|
|
|
$prop->name = $var->getName(); |
|
44
|
|
|
$prop->setType($var->getType()); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return $prop; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return Variable |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getVar($name) { |
|
54
|
|
|
$var = null; |
|
55
|
|
|
if (array_key_exists($name, $this->vars)) { |
|
56
|
|
|
$var = $this->vars[$name]; |
|
57
|
|
|
} |
|
58
|
|
|
if (!$var instanceof Variable && array_key_exists('', $this->vars)) { |
|
59
|
|
|
$var = $this->vars['']; |
|
60
|
|
|
} |
|
61
|
|
|
return $var; |
|
62
|
|
|
} |
|
63
|
|
|
public function setReturn(FQCN $fqcn) { |
|
64
|
|
|
$this->return = $fqcn; |
|
65
|
|
|
} |
|
66
|
|
|
public function getReturn() { |
|
67
|
|
|
return $this->return; |
|
68
|
|
|
} |
|
69
|
|
|
public function getDoc() { |
|
70
|
|
|
return $this->doc; |
|
71
|
|
|
} |
|
72
|
|
|
public function markInheritDoc() { |
|
73
|
|
|
$this->inheritDoc = true; |
|
74
|
|
|
} |
|
75
|
|
|
public function isInheritDoc() { |
|
76
|
|
|
return $this->inheritDoc; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private $return; |
|
80
|
|
|
private $doc = ""; |
|
81
|
|
|
private $vars = []; |
|
82
|
|
|
private $throws = []; |
|
|
|
|
|
|
83
|
|
|
private $properties = []; |
|
84
|
|
|
private $inheritDoc = false; |
|
85
|
|
|
} |
|
86
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.