The Wayback Machine - https://web.archive.org/web/20210704140411/https://github.com/permafrost-dev/php-code-search
Skip to content
main
Switch branches/tags
Code

Latest commit

Files

Permalink
Failed to load latest commit information.

php-code-search

php-code-search logo

Package Version license Test Run Status code coverage


Search PHP source code for function & method calls, variable assignments, and more.


Installation

composer require permafrost-dev/php-code-search

Searching

To search a file, use the search method. Its only parameter may be either a string containing a valid filename or an instance of \Permafrost\PhpCodeSearch\Support\File.

Function calls

To search for function calls, use the functions method before calling search.

use Permafrost\PhpCodeSearch\Searcher;

$searcher = new Searcher();

$results = $searcher
    ->functions(['strtolower', 'strtoupper'])
    ->search('./file1.php');
    
foreach($results as $result) {
    echo "Found '{$result->location->name}' on line {$result->location->startLine}" . PHP_EOL;
}

Static method calls

To search for static method calls, use the static method before calling search.

use Permafrost\PhpCodeSearch\Searcher;

$searcher = new Searcher();

$results = $searcher
    ->static(['Ray', 'Cache'])
    ->search('./app/Http/Controllers/MyController.php');
    
foreach($results as $result) {
    echo "Found '{$result->location->name}' on line {$result->location->startLine}" . PHP_EOL;
}

New class instances

To search for a class created by the new keyword, use the classes method before calling search.

use Permafrost\PhpCodeSearch\Searcher;

$searcher = new Searcher();

$results = $searcher
    ->classes(['MyClass'])
    ->search('./app/Http/Controllers/MyController.php');
    
foreach($results as $result) {
    echo "Found '{$result->location->name}' on line {$result->location->startLine}" . PHP_EOL;
}

Variable assignments

To search for a variable assignment by variable name, use the assignments method before calling search. Note: The $ should be omitted.

use Permafrost\PhpCodeSearch\Searcher;

$searcher = new Searcher();

$results = $searcher
    ->assignments(['myVar'])
    ->search('./app/Http/Controllers/MyController.php');
    
foreach($results as $result) {
    echo "Found '{$result->location->name}' on line {$result->location->startLine}" . PHP_EOL;
}

Testing

./vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Search PHP source code for function & method calls, variable assignments, and more.

Topics

Resources

License

Sponsor this project

 

Languages