-
Notifications
You must be signed in to change notification settings - Fork 54
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
New Rule to use the whereLike
clause in Laravel 11.x
#267
base: main
Are you sure you want to change the base?
Conversation
if (! $this->isObjectType($node->var, new ObjectType('Illuminate\Database\Query\Builder'))) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would be better off expanding this a little. Namely using the contract for the query builder instead of the object type.
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [MethodCall::class]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be expanded to Static calls for a Model as well, as Model::where('a', 'like', 'b')
wouldn't be covered by this rule as it uses a proxy system.
|
||
use Illuminate\Database\Query\Builder; | ||
|
||
class Fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best not to name classes in tests the same. I've found it causes weird issues. It's best to name the class WithPostgresDriver to match the file name.
return; | ||
} | ||
|
||
Assert::count($configuration, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line seems a bit redundant as we know it's an array and the key is checked. It should affect anything if the config contains more keys
Assert::keyExists($configuration, 'usingPostgresDriver'); | ||
Assert::boolean($configuration['usingPostgresDriver']); | ||
$this->usingPostgresDriver = $configuration['usingPostgresDriver']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to introduce a const for the array key that's public or just have a static method that creates the array e.g. WhereToWhereLikeRector::usingPostgresDriver()
Then update the code sample for it.
Adds a new rule
WhereToWhereLike
(open for a better name) that will migrate all the->where('name', 'like', '%Rector%')
clauses into the newwhereLike()
introduced in Laravel 11.x.