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

Allow configuring EloquentOrderByToLatestOrOldestRector #148

Conversation

johnbacon
Copy link
Contributor

Resolves #147.

  • Allows an ALLOWED_PATTERNS array of strings to apply this rule to
  • Adds additional test items for variable handling

Notes

  • The way this is implemented, it will always change created_at columns (as it did before)
  • Because static analysis cannot get the value of a variable, we instead allow for specifying variable names

Tested

  • Current test scenario
  • Scenario where no rule configuration is present

@driftingly
Copy link
Owner

We use composer docs to update the docs using symplify/rule-doc-generator.
Can you ensure your changes are compatible?

- Refined the example and some naming
- Ran `composer docs`
@johnbacon
Copy link
Contributor Author

@driftingly That should be done now! Thanks for the heads up, it wasn't compatible without changes.

Copy link
Collaborator

@peterfox peterfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple things I'd consider changing

Comment on lines 15 to 16
$query->orderBy($unallowed_variable_name);
$query->orderBy('unallowed_column_name');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be better to exist in their own file like skip_if_not_eloquent_builder.php.inc

// skip_if_column_not_allowed.php.inc
<?php

namespace RectorLaravel\Tests\Rector\Cast\DatabaseExpressionCastsToMethodCall\Fixture;

$query->orderBy($unallowed_variable_name);
$query->orderBy('unallowed_column_name');

?>

Copy link
Contributor Author

@johnbacon johnbacon Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this, but I thought these would be unallowed not because they weren't an instance of Builder but because they weren't desired to be automatically refactored. Does it still make sense to move to a different file? I'm not familiar with best practices in this regard.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @peterfox is saying to create a file called skip_if_column_not_allowed.php.inc or skip_if_column_not_configured.php.inc similar to how he did with with the EloquentOrderByToLatestOrOldestRector fixtures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! At least... I think I got it. I don't have any experience with this at this point, besides following orders. Please let me know if I need to do something else!

@driftingly driftingly merged commit a52689f into driftingly:main Dec 8, 2023
4 checks passed
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.

Allow configuration with EloquentOrderByToLatestOrOldestRector rule
3 participants