Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Code Search Laravel Package

permafrost-dev/php-code-search

PHP library for searching code across projects and repositories. Provides fast, programmable text/pattern queries with useful match context and filtering, making it easier to locate symbols, usages, or snippets during audits, refactors, and CI tooling.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require permafrost-dev/php-code-search
    

    Add to composer.json under require-dev if only for local development.

  2. First Use Case Search for all method calls to Auth::login() in your Laravel app:

    use Permafrost\CodeSearch\Searcher;
    
    $searcher = new Searcher();
    $results = $searcher->search(
        base_path('app'),
        'Auth::login('
    );
    
    foreach ($results as $result) {
        echo "Found in: {$result['file']} at line {$result['line']}\n";
    }
    
  3. Where to Look First

    • Documentation (if available; check README)
    • Searcher class methods: search(), searchInFiles(), searchForFunctions()
    • Default search patterns (e.g., regex-based) in src/Permafrost/CodeSearch/

Implementation Patterns

Core Workflows

  1. Project-Wide Searches

    $searcher = new Searcher();
    $results = $searcher->search(
        base_path(), // Root directory
        '->where('   // Look for Eloquent where clauses
    );
    
  2. File-Specific Searches

    $results = $searcher->searchInFiles(
        [app_path('Http/Controllers/UserController.php')],
        'dd('
    );
    
  3. Function/Method Call Tracking

    // Find all calls to a custom helper
    $results = $searcher->searchForFunctions(
        'my_custom_helper',
        base_path('app')
    );
    
  4. Integration with Laravel Artisan Create a custom command:

    use Permafrost\CodeSearch\Searcher;
    
    class SearchCommand extends Command {
        protected $signature = 'search:code {query} {--directory=}';
        public function handle(Searcher $searcher) {
            $results = $searcher->search(
                $this->option('directory') ?? base_path(),
                $this->argument('query')
            );
            $this->line(print_r($results, true));
        }
    }
    

Advanced Patterns

  • Exclude Directories

    $searcher->search(base_path(), '->', [
        'exclude' => ['vendor', 'storage']
    ]);
    
  • Case-Insensitive Search

    $searcher->search(base_path(), 'auth::', [
        'flags' => Searcher::FLAG_CASE_INSENSITIVE
    ]);
    
  • Callback Filtering

    $results = $searcher->search(base_path(), '->')
        ->filter(fn($result) => str_contains($result['file'], 'Controller'));
    

Gotchas and Tips

Pitfalls

  1. Performance with Large Codebases

    • Avoid searching entire vendor/ or node_modules/ directories.
    • Use --directory to limit scope in CLI commands.
  2. False Positives in Regex

    • Auth::login( may match Auth::loginUser().
    • Use precise patterns like Auth::login\( (with escaped parentheses).
  3. Line Number Accuracy

    • Results may slightly misalign if files have mixed line endings (\n vs \r\n).
    • Normalize files before searching if needed:
      $searcher->normalizeFiles([$filePath]);
      
  4. Multibyte Characters

    • UTF-8 filenames/directories may cause issues on Windows.
    • Prefer forward slashes (/).

Debugging Tips

  • Enable Verbose Output
    $searcher->setVerbose(true);
    
  • Check File Permissions Ensure the searcher has read access to target directories.
  • Validate Regex Test patterns in tools like regex101.com first.

Extension Points

  1. Custom Search Patterns Extend Searcher to add domain-specific patterns:

    class LaravelSearcher extends Searcher {
        public function searchForEloquentQueries($query) {
            return $this->search(base_path(), $query, [
                'flags' => self::FLAG_CASE_INSENSITIVE
            ]);
        }
    }
    
  2. Post-Processing Results Use ->map() or ->filter() to transform results:

    $results->map(fn($r) => [
        'file' => str_replace(base_path(), '', $r['file']),
        'line' => $r['line'],
        'context' => $this->getContext($r['file'], $r['line'])
    ]);
    
  3. Integration with IDEs Export results to JSON for IDE plugins:

    file_put_contents(
        storage_path('code-search.json'),
        json_encode($results)
    );
    

Config Quirks

  • Default Excludes The package may silently skip hidden files (e.g., .env). Override with:
    $searcher->setExcludes([]);
    
  • Memory Limits Large searches may hit PHP’s memory_limit. Increase if needed:
    memory_limit = 512M
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport