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

Add method exclusions for EloquentMagicMethodToQueryBuilderRector #171

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

tanerkay
Copy link
Contributor

Add ability to exclude methods from the rector EloquentMagicMethodToQueryBuilderRector

I found this beneficial for find() and findOrFail(), as these are often used in simple statements without chaining, and subjectively appear overly verbose when ::query()-> is added to them.

e.g.

<?php

declare(strict_types=1);

use RectorLaravel\Rector\MethodCall\EloquentOrderByToLatestOrOldestRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
    $containerConfigurator->extension('rectorConfig', [
        [
            'class' => EloquentMagicMethodToQueryBuilderRector::class,
            'configuration' => [
                'exclude_methods' => [
                    'find',
                    'findOrFail',
                ],
            ],
        ],
    ]);
};

 use App\Models\User;

$user = User::find(1); // no change

-$user = User::where('x', 1);
+$user = User::query()->where('x', 1);

@GeniJaho GeniJaho merged commit 6bf7ca5 into driftingly:main Jan 22, 2024
5 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