spatie/x-ray
Scan your codebase for Ray debugging calls (ray(), rd(), Ray::*, ->ray()) and list where they occur so you can remove them before deploy. Supports multiple paths, ignores, snippets/summary, GitHub Actions annotations, and CI-friendly exit codes.
Installation:
composer require spatie/x-ray
Add the service provider to config/app.php:
Spatie\XRay\XRayServiceProvider::class,
First Scan:
Use the scan() method to detect Ray calls in your project:
use Spatie\XRay\Facades\XRay;
$results = XRay::scan(base_path());
Outputs a structured array of found Ray calls with file paths, line numbers, and context.
Quick Use Case: Run a one-off scan during debugging to locate all Ray logging calls in a specific directory:
php artisan xray:scan app/Http/Controllers
Integrating with CI/CD: Add a GitHub Action or GitLab CI step to scan for Ray calls before merging:
# .github/workflows/xray.yml
- name: Scan for Ray calls
run: php artisan xray:scan app --format=json > ray_calls.json
Pre-Commit Hooks:
Use husky or pre-commit to block commits with new Ray calls:
composer require --dev spatie/x-ray
Add to .husky/pre-commit:
php artisan xray:scan --fail-on-new
Dynamic Scanning in Tests: Verify Ray calls are removed after refactoring:
public function test_ray_calls_removed()
{
$results = XRay::scan(base_path('app'));
$this->assertEmpty($results, 'Ray calls found in app directory');
}
XRay::scan(base_path())->toJson()->save('ray_calls.json');
vendor/ or tests/ in scans:
XRay::scan(base_path())->ignoreDirectories(['vendor', 'tests']);
php artisan xray:scan --path=app/Http --format=table
False Positives:
Ray:: as a call even in comments or strings.--strict to avoid partial matches or whitelist files:
XRay::scan(base_path())->whitelist(['app/Helpers/ray-helpers.php']);
Performance:
XRay::scan(base_path())->cacheFor(minutes: 60);
Edge Cases:
${class}::ray()) won’t be detected.--regex to customize patterns:
XRay::scan(base_path())->useRegex('/\bRay::\w+/');
php artisan xray:scan --verbose
php artisan xray:scan --dry-run
Log::):
XRay::extend(function (Scanner $scanner) {
$scanner->addPattern('/Log::\w+/');
});
scanned event to automate fixes:
XRay::scanned(function (array $results) {
foreach ($results as $result) {
// Replace Ray calls with Log:: here
}
});
config/xray.php:
'ignored_directories' => [
'vendor',
'node_modules',
'storage/logs',
],
How can I help you explore Laravel packages today?