plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Request] Refactor/inspection for orderBy

Open olivernybroe opened this issue 5 years ago • 6 comments

Description

When using a query builder, it could be cool with suggestions for how to write it smarter. So utilising the helper methods for writing orderBy clauses shorter.

Examples

For example, having the following code

$query->orderBy('read_at', 'desc')

Can be rewritten to the following scenarios

$query->orderByDesc('read_at')
$query->latest('read_at')

And this

$query->orderBy('created_at', 'asc')

Can be rewritten to the two following scenarios

$query->orderBy('created_at')
$query->oldest()

Problems

When to suggest orderBy over latest/oldest

Either always show both scenarios when refactor and if one of them is chosen then the inspection is fine with it. Or look at the field, so if it is a date field or ends with _at then use latest/oldest syntax over orderBy syntax.

olivernybroe avatar Aug 31 '20 10:08 olivernybroe

Nice. I'll think about it. Thanks. BTW,

$query->orderBy('read_at', 'desc')

Do you have completion for 'read_at' and other fields there?

adelf avatar Aug 31 '20 10:08 adelf

@adelf Yep! 👍

olivernybroe avatar Aug 31 '20 11:08 olivernybroe

I think the problem of hints for the latest and oldest methods can be attributed to the current issue.

image

image

image

andrey-helldar avatar Jan 22 '21 22:01 andrey-helldar

@andrey-helldar I complete only date fields for oldest/newest methods. Phpdoc for these methods: "Add an "order by" clause for a timestamp to the query." However, I can add all fields there...

adelf avatar Feb 14 '21 14:02 adelf

@adelf, I personally like to call oldesr and latest methods instead of orderBy. Therefore, I would prefer to be able to fill quickly 🙂

andrey-helldar avatar Feb 14 '21 14:02 andrey-helldar

Whatever... it will complete all fields in the next version.

adelf avatar Feb 14 '21 14:02 adelf