Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor If statements to use helpers with conditionals and provides a set #194

Merged
merged 7 commits into from
Mar 11, 2024

Conversation

peterfox
Copy link
Collaborator

@peterfox peterfox commented Mar 4, 2024

Changes

  • Adds rules for abort_if and report_if function calls as replacement for If statements containing abort or report.
  • Adds tests for both rules
  • Adds a set to handle the two new rules and the previous throw_if related rule. The set making it easier to just use all of them.
  • Adds the config dir to rector

Why

Makes sense to cover all the possible helpers and have a set that covers the three scenarios. The only one missing would be the Dispatchable trait static calls (dispatchIf) but it would require a new rule and feels a bit more niche compared to the helpers.

@peterfox peterfox added the enhancement New feature or request label Mar 4, 2024
@peterfox peterfox self-assigned this Mar 4, 2024
…ort-to-abort-if

# Conflicts:
#	docs/rector_rules_overview.md
@driftingly driftingly merged commit 68db7e9 into main Mar 11, 2024
5 checks passed
@driftingly driftingly deleted the feature/if-and-abort-to-abort-if branch March 11, 2024 21:27
@johnbacon
Copy link
Contributor

I may be missing something, but this doesn't seem to be available via https://github.com/driftingly/rector-laravel/blob/eefaf3ef1186a4f07b50988de402b30b87143ed7/src/Set/LaravelSetList.php. Is there another way to use it? (Thank you!!)

@GeniJaho
Copy link
Collaborator

@johnbacon You're right, we're missing a constant for it. We'll probably add one soon.
Another way to use it is to include the three rules manually:

$rectorConfig->rule(AbortIfRector::class);
$rectorConfig->rule(ReportIfRector::class);
$rectorConfig->rule(ThrowIfRector::class);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants