Skip to content

Conversation

@FlorianRiquelme
Copy link

The RemoveRayCallRector only removed simple ray() function calls but failed to remove chained method calls like:

  • ray()->label('debug')
  • ray($data)->red()
  • ray($data)->red()->small()

To fix this I added a recursive helper method isRayCall() that traverses the method chains to check if they are originally from a ray() function call.

I couldn't find a way to properly add automated tests for this, so here is a way to manually verify this:

The fixture:

<?php

$data = ['key' => 'value'];

// This is working currently
ray($data);

// These should be removed too
ray()->label('debug');
ray($data)->red();
ray($data)->red()->small();
ray()->green()->large()->label('test');

// Not sure if it should be removed
$test = ray();

// Should not be removed
$logger = new stdClass();
$logger->info('message')->withContext(['user' => 'john']);

And the command to execute this: vendor/bin/rector process fixture.php --config remove-ray-rector.php --dry-run

I'm not sure about automatically removing code such as $test = ray();, so this would still be untouched for now. Clearly this should not go into production as is, any opinions on this?

Previously only simple ray() calls were removed. This fix adds recursive
traversal to properly detect and remove chained calls like ray()->label()
and ray($data)->red()->small().

The isRayCall() helper method now recursively checks if a method chain
originates from a ray() function call, fixing the issue while preserving
non-ray method chains.
@FlorianRiquelme FlorianRiquelme marked this pull request as ready for review October 17, 2025 05:40
@CasperLaiTW
Copy link

CasperLaiTW commented Nov 7, 2025

I got same issue. The RemoveRayCallRector only removed simple ray() function, can't remove method chaining.

The PR is working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants