| @@ 221-249 (lines=29) @@ | ||
| 218 | * |
|
| 219 | * @param VisitorInterface $visitor |
|
| 220 | */ |
|
| 221 | public function walk(VisitorInterface $visitor) |
|
| 222 | { |
|
| 223 | $node = $this; |
|
| 224 | $result = $visitor->enterNode($node); |
|
| 225 | if ($result instanceof NodeInterface) { |
|
| 226 | $node = $result; |
|
| 227 | } |
|
| 228 | if ($result !== NodeTraverser::DONT_TRAVERSE_CHILDREN) { |
|
| 229 | if (is_array($this->refClause)) { |
|
| 230 | foreach ($this->refClause as $key => $operand) { |
|
| 231 | $result2 = $operand->walk($visitor); |
|
| 232 | if ($result2 === NodeTraverser::REMOVE_NODE) { |
|
| 233 | unset($this->refClause[$key]); |
|
| 234 | } elseif ($result2 instanceof NodeInterface) { |
|
| 235 | $this->refClause[$key] = $result2; |
|
| 236 | } |
|
| 237 | } |
|
| 238 | } elseif ($this->refClause) { |
|
| 239 | $result2 = $this->refClause->walk($visitor); |
|
| 240 | if ($result2 === NodeTraverser::REMOVE_NODE) { |
|
| 241 | $this->refClause = null; |
|
| 242 | } elseif ($result2 instanceof NodeInterface) { |
|
| 243 | $this->refClause = $result2; |
|
| 244 | } |
|
| 245 | } |
|
| 246 | } |
|
| 247 | ||
| 248 | return $visitor->leaveNode($node); |
|
| 249 | } |
|
| 250 | } |
|
| 251 | ||
| @@ 235-263 (lines=29) @@ | ||
| 232 | * |
|
| 233 | * @param VisitorInterface $visitor |
|
| 234 | */ |
|
| 235 | public function walk(VisitorInterface $visitor) |
|
| 236 | { |
|
| 237 | $node = $this; |
|
| 238 | $result = $visitor->enterNode($node); |
|
| 239 | if ($result instanceof NodeInterface) { |
|
| 240 | $node = $result; |
|
| 241 | } |
|
| 242 | if ($result !== NodeTraverser::DONT_TRAVERSE_CHILDREN) { |
|
| 243 | if (is_array($this->subTree)) { |
|
| 244 | foreach ($this->subTree as $key => $operand) { |
|
| 245 | $result2 = $operand->walk($visitor); |
|
| 246 | if ($result2 === NodeTraverser::REMOVE_NODE) { |
|
| 247 | unset($this->subTree[$key]); |
|
| 248 | } elseif ($result2 instanceof NodeInterface) { |
|
| 249 | $this->subTree[$key] = $result2; |
|
| 250 | } |
|
| 251 | } |
|
| 252 | } else { |
|
| 253 | $result2 = $this->subTree->walk($visitor); |
|
| 254 | if ($result2 === NodeTraverser::REMOVE_NODE) { |
|
| 255 | $this->subTree = []; |
|
| 256 | } elseif ($result2 instanceof NodeInterface) { |
|
| 257 | $this->subTree = $result2; |
|
| 258 | } |
|
| 259 | } |
|
| 260 | } |
|
| 261 | ||
| 262 | return $visitor->leaveNode($node); |
|
| 263 | } |
|
| 264 | ||
| 265 | /** |
|
| 266 | * Returns if this node should be removed from the tree. |
|