driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
540 stars 52 forks source link

Add JsonCallToExplicitJsonCallRector #158

Closed Stoffo closed 9 months ago

Stoffo commented 9 months ago

Adds the following rule:

JsonCallToExplicitJsonCallRector

Changes Method Calls of $this->json() in PHPUnit Feature Tests to the more explicit version $this->postJson(), $this->putJson(), etc..

-$this->json("POST", "/api/v1/users", $data);
+$this->postJson("/api/v1/users", $data);

-$this->json("PUT", "/api/v1/users", $data);
+$this->putJson("/api/v1/users", $data);
Stoffo commented 9 months ago

@driftingly had to fix some Code Style Issues, now the tests should be green

driftingly commented 9 months ago

Hi @Stoffo! Thanks for your work on this! I recently switched the code style to be more in line with Laravel style. Can you pull down the latest changes to this branch and run composer fix and composer rector to fix the last issues here? You may also need to fix a PHPStan error that I saw pop up.

driftingly commented 9 months ago

This will fix the PHPStan issues:

    public function refactor(Node $node): ?Node
    {
        if ($node instanceof MethodCall) {
            return $this->updateCall($node);
        }

        return null;
    }
Stoffo commented 9 months ago

@driftingly Thanks for tips! I rebased the branch and ran the tools again 👍🏻

driftingly commented 9 months ago

Thanks! I'll merge in as-is and clean up in main