stronk7/php-search

Semantic-like PHP searches using AST structures generated by php-parser

v0.2.9 2024-06-19 12:04 UTC

This package is auto-updated.

Last update: 2024-11-19 13:09:41 UTC


README

composer require stronk7/php-search ;-)

USAGE

Usage: php-search [operations] file1.php [file2.php ...]
   or: php-search [operations] "<?php code"
Perform some accurate PHP searches using AST structures generated by php-parser.

Operations is a list of the following options:

    -e, --expression        Expression defining the search within the AST. Supports:
                                - statements (if, continue, foreach...).
                                - "loop" as equivalent of for|foreach|do|while
                                - functions and methods always specifying ():
                                    - "function" for global function declarations.
                                    - "method" for class method declarations.
                                    - global, object (->) and class (::) method calls.
                                - / separator for nested searching.
                                - | separator for logical OR searching.
    -d, --dump              Dump AST nodes using NodeDumper.
    -C, --with-comments     Show comments/phpdocs in AST node dumps.
    -P, --with-positions    Show positions in AST node dumps.

    -h, --help              Display this page.

Examples:
    php-search -e 'switch / case / continue' *.php
        Search for all continue ocurrences within switch and case statements.

    php-search -e 'loop / \->get_recordset()|\->get_records()' file.php
        Search for all the calls to get_recordset() OR get_records() methods
        within a loop (loop expands to for|foreach|while|do).

    php-search -e 'method setUp() / \->resetAfterTest()' file.php
        Search for all the setUp() method implementations performing
        a call to resetAfterTest().

    grep|ag -lr 'xxxx' * | xargs php-search -e 'something / complex / xxxx'
        Tip: When there are many files it's recommended to reduce them by name (find)
        or contents (grep, ag...) in order to pass to php-search a reduced list.

    php-search -e 'something()' *.php | xargs do_something
        Search for all the calls to something() returning 1-line matches
        (like grep, ag...) for easier post-process.

    php-search -d -C -P file.php
        Dumps AST nodes, with comments and positions from file.php.

Expansions:
    loop: for|foreach|while|do
    use:  use|traituse

LICENSE

Whatever you need, being OSI. BSD New (3-Clause) by default.