PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / vendor / nikic / php-parser / lib / PhpParser / NodeVisitor / FirstFindingVisitor.php

FirstFindingVisitor.php in WPIDE – File Manager & Code Editor 3.5.9, at vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php

51 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\NodeVisitor;
4
5 use PhpParser\Node;
6 use PhpParser\NodeTraverser;
7 use PhpParser\NodeVisitorAbstract;
8
9 /**
10 * This visitor can be used to find the first node satisfying some criterion determined by
11 * a filter callback.
12 */
13 class FirstFindingVisitor extends NodeVisitorAbstract
14 {
15 /** @var callable Filter callback */
16 protected $filterCallback;
17 /** @var null|Node Found node */
18 protected $foundNode;
19
20 public function __construct(callable $filterCallback) {
21 $this->filterCallback = $filterCallback;
22 }
23
24 /**
25 * Get found node satisfying the filter callback.
26 *
27 * Returns null if no node satisfies the filter callback.
28 *
29 * @return null|Node Found node (or null if not found)
30 */
31 public function getFoundNode() {
32 return $this->foundNode;
33 }
34
35 public function beforeTraverse(array $nodes) {
36 $this->foundNode = null;
37
38 return null;
39 }
40
41 public function enterNode(Node $node) {
42 $filterCallback = $this->filterCallback;
43 if ($filterCallback($node)) {
44 $this->foundNode = $node;
45 return NodeTraverser::STOP_TRAVERSAL;
46 }
47
48 return null;
49 }
50 }
51