PHP 8.2.31
Preview: NodeFinder.php Size: 2.55 KB
//opt/cpanel/ea-wappspector/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php

<?php declare(strict_types=1);

namespace PhpParser;

use PhpParser\NodeVisitor\FindingVisitor;
use PhpParser\NodeVisitor\FirstFindingVisitor;

class NodeFinder {
    /**
     * Find all nodes satisfying a filter callback.
     *
     * @param Node|Node[] $nodes Single node or array of nodes to search in
     * @param callable $filter Filter callback: function(Node $node) : bool
     *
     * @return Node[] Found nodes satisfying the filter callback
     */
    public function find($nodes, callable $filter): array {
        if ($nodes === []) {
            return [];
        }

        if (!is_array($nodes)) {
            $nodes = [$nodes];
        }

        $visitor = new FindingVisitor($filter);

        $traverser = new NodeTraverser($visitor);
        $traverser->traverse($nodes);

        return $visitor->getFoundNodes();
    }

    /**
     * Find all nodes that are instances of a certain class.

     * @template TNode as Node
     *
     * @param Node|Node[] $nodes Single node or array of nodes to search in
     * @param class-string<TNode> $class Class name
     *
     * @return TNode[] Found nodes (all instances of $class)
     */
    public function findInstanceOf($nodes, string $class): array {
        return $this->find($nodes, function ($node) use ($class) {
            return $node instanceof $class;
        });
    }

    /**
     * Find first node satisfying a filter callback.
     *
     * @param Node|Node[] $nodes Single node or array of nodes to search in
     * @param callable $filter Filter callback: function(Node $node) : bool
     *
     * @return null|Node Found node (or null if none found)
     */
    public function findFirst($nodes, callable $filter): ?Node {
        if ($nodes === []) {
            return null;
        }

        if (!is_array($nodes)) {
            $nodes = [$nodes];
        }

        $visitor = new FirstFindingVisitor($filter);

        $traverser = new NodeTraverser($visitor);
        $traverser->traverse($nodes);

        return $visitor->getFoundNode();
    }

    /**
     * Find first node that is an instance of a certain class.
     *
     * @template TNode as Node
     *
     * @param Node|Node[] $nodes Single node or array of nodes to search in
     * @param class-string<TNode> $class Class name
     *
     * @return null|TNode Found node, which is an instance of $class (or null if none found)
     */
    public function findFirstInstanceOf($nodes, string $class): ?Node {
        return $this->findFirst($nodes, function ($node) use ($class) {
            return $node instanceof $class;
        });
    }
}

Directory Contents

Dirs: 9 × Files: 28

Name Size Perms Modified Actions
Builder DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
Comment DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
Internal DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
Lexer DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
Node DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
Parser DIR
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
- drwxr-xr-x 2025-12-06 11:56:16
Edit Download
202 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
10.30 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
9.73 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
6.75 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
2.46 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
112 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
9.33 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
4.84 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
300 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
3.44 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
4.26 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
2.71 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
9.82 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
4.03 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
5.24 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
10.24 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
2.55 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
10.09 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
598 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
4.08 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
447 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
765 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download
51.59 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
1.41 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
4.73 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
1.66 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
71.24 KB lrw-r--r-- 2025-12-06 11:56:16
Edit Download
487 B lrw-r--r-- 2025-12-06 11:56:16
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).