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

Adds EloquentWhereRelationTypeHintingParameterRector rule #138

Conversation

peterfox
Copy link
Collaborator

Adds the following rule:

EloquentWhereRelationTypeHintingParameterRector

Add type hinting to where relation has methods e.g. whereHas, orWhereHas, whereDoesntHave, orWhereDoesntHave, whereHasMorph, orWhereHasMorph, whereDoesntHaveMorph, orWhereDoesntHaveMorph

-User::whereHas('posts', function ($query) {
+User::whereHas('posts', function (\Illuminate\Contracts\Database\Eloquent\Builder $query) {
     $query->where('is_published', true);
 });

-$query->whereHas('posts', function ($query) {
+$query->whereHas('posts', function (\Illuminate\Contracts\Database\Eloquent\Builder $query) {
     $query->where('is_published', true);
 });

This rule covers scenarios where the Model static proxy passes the method call to a query builder by forwarded calls and on the Builder contract. This will refactor both closures and arrow functions.

@peterfox peterfox marked this pull request as ready for review September 17, 2023 16:36
@peterfox peterfox marked this pull request as draft September 18, 2023 11:45
peterfox and others added 4 commits September 18, 2023 19:08
commit c664be4
Author: Clément Birklé <clement.birkle@gmail.com>
Date:   Mon Sep 18 22:16:17 2023 +0200

    Add EloquentMagicMethodToQueryBuilderRector rule (driftingly#132)

    * Add EloquentMagicMethodToQueryBuilderRector rule

    * Fix PHPStan errors

commit 2af4076
Author: Andrew Miller <ikari7789@yahoo.com>
Date:   Tue Sep 19 05:14:23 2023 +0900

    Remove MethodCallRename rule from Laravel80 ruleset (driftingly#134)

    It references the commit where the function was "renamed", but the next commit in the laravel/framework repository is re-adding the function.

    laravel/framework@8e0914e

    As `assertExactJson()` and `assertSimilarJson()` have very different expectations, I think this could change could inadvertently alter tests to be less accurate.

    Co-authored-by: Anthony Clark <anthonyclark@gmail.com>
…osure-parameter

# Conflicts:
#	docs/rector_rules_overview.md
@peterfox peterfox marked this pull request as ready for review September 18, 2023 21:03
@driftingly driftingly merged commit 02f77b0 into driftingly:main Sep 22, 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.

2 participants