Back to overview

Automatically remove Ray calls from your code

24 January 2024

Image of Tim

Tim

When debugging, we can scatter a bunch of Ray calls throughout our code, and sometimes we forget to remove one or two before committing our code. To keep a clean codebase, this is something we want to avoid.

To help you clean up your debug code, we have now added a mechanism to remove all Ray calls from your code easily. There are two ways of using it:

Using a simple command

If you are using laravel-ray we added an artisan command you can run:

php artisan ray:clean

And poof... all the ray calls in your project are now gone!

We also added a framework-agnostic command for framework agnostic PHP projects:

./vendor/bin/remove-ray.sh <path>

These commands will remove all Ray calls and Ray macro's from your code.

For example:

function users(string $teamUid) 
{
  ray($teamUid);
  
  $users = User::where('team_uid', $uid)->get();
  
  $users->ray();
    
  return $users;
}

This will be cleaned up and give the following result:

function users(string $teamUid) 
{
  $users = User::where('team_uid', $uid)->get();
    
  return $users;
}

How this works

Under the hood, we are using Rector for this. Rector is a CLI tool that helps you automate the refactoring of your code. Rector has many handy "rules" available and allows you to add your own, which is what we did.

If you are already using Rector, you can add our new Rector rule to your existing Rector config (rector.php):

use Spatie\Ray\Rector\RemoveRayCallRector;

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

After adding this, all Ray calls will be removed every time you run Rector. To fully automate this, you can run Rector with a pre-commit hook or add it to your CLI.

Stay in the loop with updates & promotions for Ray

We only send a few emails a year.

Debug without breaking your flow

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

Licenses are valid for 1 year and managed through Spatie. Licenses purchased before Ray 3 remain valid. VAT is calculated at checkout.