⚡️ Ray 3.0 launch sale! Discounts and lifetime licenses available for d h m s

Detecting & removing Ray calls

To avoid shipping your code with ray() calls in it, you can use various tools to detect and remove them from your codebase.

#Detecting Ray calls

#Using PHPStan

Ray provides a custom PHPStan rule that lets you detect remaining Ray calls in your application.

rules:
    - Spatie\Ray\PHPStan\RemainingRayCallRule

All remaining Ray calls would then be reported by PHPStan.

screenshot

#Using X-Ray

Ray provides a first-party package named x-ray, allowing you to detect remaining Ray calls in your application. This package does NOT remove the calls, it simply displays their locations so they can be removed manually.

The exit code of the x-ray command is zero if no Ray calls are found, and non-zero if calls are found. This allows the package to be used in an automated environment such as Github Workflows.

Installation

Install the package in your PHP or Laravel project:

composer require spatie/x-ray --dev

Usage

Specify one or more valid path names and/or filenames to scan:

./vendor/bin/x-ray ./app/Actions/MyAction.php ./app/Models/*.php ./tests --snippets

Display a summary table of the located calls within ./src and ./tests while also ignoring some files:

./vendor/bin/x-ray \
  --summary \
  --ignore src/MyClass.php \
  --ignore 'test/fixtures/*.php' \
  ./src ./tests

Display each filename & pass/fail status, along with compact results:

./vendor/bin/x-ray ./app --compact --verbose

Available options

Flag Description
--compact or -c Minimal output. Display each result on a single line.
--github or -g GitHub Annotation output. Use error command to create annotation. Useful when you are running x-ray within GitHub Actions.
--ignore or -i Ignore a file or path, can be specified multiple times. Accepts glob patterns.
--no-progress or -P Don't display the progress bar while scanning files
--snippets or -S Display code snippets from located calls
--summary or -s Display a summary of the files/calls discovered
--verbose or -v Display each filename and pass/fail status while scanning. Implies --no-progress.

Find examples for how to add x-ray to your Github workflows at spatie/x-ray.

#Removing Ray calls

#Using Rector

If you are already using Rector this can be done by adding a rule to your rector.php config file:

use Spatie\Ray\Rector\RemoveRayCallRector;

$rectorConfig->rule(RemoveRayCallRector::class);

#Using the remove script

If you are not using Rector you can use the script provided by the package:

./vendor/bin/remove-ray.sh <path>
Help us improve this page

Debug without breaking your flow

Ray keeps all your debug output neatly organized in a dedicated desktop app.

Launch sale! Lifetime licenses also available

Ray licenses are valid for 1 year and managed through Spatie. VAT is calculated during checkout.