|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Project\Collection; |
|
4
|
|
|
|
|
5
|
|
|
use Padawan\Domain\Project\Node\MethodData; |
|
6
|
|
|
|
|
7
|
|
|
class Specification |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param $mode string |
|
11
|
|
|
* @param $static int|bool |
|
12
|
|
|
* @param $magic bool |
|
13
|
|
|
*/ |
|
14
|
|
|
public function __construct($mode = 'private', $static = false, $magic = false) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->expandMode($mode); |
|
17
|
|
|
$this->showStatic = $static; |
|
18
|
|
|
$this->magic = $magic; |
|
19
|
|
|
} |
|
20
|
|
|
public function satisfy($node) |
|
21
|
|
|
{ |
|
22
|
|
|
if (!$this->allowProtected && $node->isProtected()) { |
|
23
|
|
|
return false; |
|
24
|
|
|
} |
|
25
|
|
|
if (!$this->allowPrivate && $node->isPrivate()) { |
|
26
|
|
|
return false; |
|
27
|
|
|
} |
|
28
|
|
|
if ($node instanceof MethodData) { |
|
29
|
|
|
if ($node->isMagic() && !$this->magic) { |
|
30
|
|
|
return false; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
if ($this->showStatic < 2 && $node->isStatic() != $this->showStatic) { |
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
public function isStatic() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->showStatic; |
|
41
|
|
|
} |
|
42
|
|
|
public function isMagic() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->magic; |
|
45
|
|
|
} |
|
46
|
|
|
public function getParentMode() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->parentMode; |
|
49
|
|
|
} |
|
50
|
|
|
protected function expandMode($mode) |
|
51
|
|
|
{ |
|
52
|
|
|
if ($mode === 'private') { |
|
53
|
|
|
$this->allowProtected = $this->allowPrivate = true; |
|
54
|
|
|
$this->parentMode = 'protected'; |
|
55
|
|
|
} elseif ($mode === 'protected') { |
|
56
|
|
|
$this->allowProtected = true; |
|
57
|
|
|
$this->allowPrivate = false; |
|
58
|
|
|
$this->parentMode = 'protected'; |
|
59
|
|
|
} else { |
|
60
|
|
|
$this->allowProtected = $this->allowPrivate = false; |
|
61
|
|
|
$this->parentMode = 'public'; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private $allowProtected; |
|
66
|
|
|
private $allowPrivate; |
|
67
|
|
|
private $showStatic; |
|
68
|
|
|
private $magic; |
|
69
|
|
|
private $parentMode; |
|
70
|
|
|
} |
|
71
|
|
|
|