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

Search PHP projects by symbol or text to quickly find classes, methods, functions, and constants across your codebase. Fast, lightweight code search for local repositories, useful for audits, refactors, and navigating large Laravel or PHP applications.

View on GitHub
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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php