1 | <?php |
||
26 | abstract class BaseNode |
||
27 | { |
||
28 | /** |
||
29 | * @var AST |
||
30 | */ |
||
31 | protected $ast; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $methodName = ''; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $methodOffset = 0; |
||
42 | |||
43 | /** |
||
44 | * @param AST $ast |
||
45 | */ |
||
46 | 202 | public function __construct(AST $ast) |
|
47 | { |
||
48 | 202 | $this->ast = $ast; |
|
49 | 202 | } |
|
50 | |||
51 | abstract public function getNode() : BaseToken; |
||
52 | |||
53 | /** |
||
54 | * Looks ahead, but does not move the pointer. |
||
55 | */ |
||
56 | 194 | protected function hasMethodCall() : bool |
|
57 | { |
||
58 | 194 | $stackClone = $this->ast->getStack()->getClone(); |
|
59 | |||
60 | 194 | while ($stackClone->valid()) { |
|
61 | 194 | $stackClone->next(); |
|
62 | |||
63 | 194 | if (!$token = $stackClone->current()) { |
|
64 | 102 | break; |
|
65 | 192 | } elseif ($this->isIgnoredToken($token)) { |
|
66 | 130 | continue; |
|
67 | } elseif ($token instanceof TokenMethod) { |
||
68 | 108 | $this->methodName = $token->getValue(); |
|
69 | 108 | $this->methodOffset = $token->getOffset(); |
|
70 | |||
71 | 108 | return true; |
|
72 | } else { |
||
73 | 172 | break; |
|
74 | } |
||
75 | } |
||
76 | |||
77 | 174 | return false; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @throws ParserException |
||
82 | */ |
||
83 | 108 | public function getMethod(BaseToken $token) : CallableFunction |
|
109 | |||
110 | 108 | private function getMethodName() : string |
|
111 | { |
||
112 | do { |
||
113 | 108 | $this->ast->next(); |
|
114 | 108 | } while ($this->ast->getStack()->current()->getOffset() < $this->methodOffset); |
|
115 | |||
116 | 108 | return trim(ltrim(rtrim($this->methodName, "\r\n("), '.')); |
|
117 | } |
||
118 | |||
119 | 52 | public function getArrayItems() : TokenCollection |
|
123 | |||
124 | 122 | public function getArguments() : TokenCollection |
|
125 | { |
||
126 | 122 | return $this->getCommaSeparatedValues(')'); |
|
128 | |||
129 | /** |
||
130 | * @throws ParserException |
||
131 | */ |
||
132 | 144 | private function getCommaSeparatedValues(string $stopAt) : TokenCollection |
|
192 | |||
193 | 192 | private function isIgnoredToken(BaseToken $token) : bool |
|
201 | } |
||
202 |