Closed johnbacon closed 9 months ago
@johnbacon what's your thoughts, a list of columns or simply a regex to match? At current the rule will refactor if a variable is used. If this was enabled. It would only refactor with string literals.
@peterfox The implementation allows for wildcards and a list of columns, but do you feel regex would provide more benefit on top of that?
The fact that static analysis can't determine the name of a column within a variable was a bummer to learn. I "got around" that by allowing you to specify the name of a variable, e.g. '$columnName'
. But if you always want to refactor all variables in an orderBy()
, I'm not sure what would be best. Maybe an additional option you config? Maybe defining '$*'
or similar would work?
Examining variable names is a bit risky. I'd likely stick to string literals. Regex, to me, makes the most sense rather than listing all possibilities someone might have. Wildcard could work, but sometimes it's more effort when Regex is more flexible, and the example of ends with _at
would be easy enough.
Is that something you could possibly lend a hand on? I'm less comfortable with regex and even more so in the Laravel/Rector ecosystem, unfortunately.
@johnbacon Sure, I'll see if I can find time to work on it.
By default, EloquentOrderByToLatestOrOldestRector modifies all
orderBy
andorderByDesc
methods to uselatest()
oroldest()
instead.Our team feels we'd like to do this only regarding timestamps, as
oldest('name')
or similar could be confusing.As such, some configuration allowing for explicit column names you'd like to change to
oldest()
orlatest()
is desired.This suggestion was also briefly mentioned in the relevant PR: