Skip to content

Prefer placing services before query parameters #18735

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

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

MWJeff
Copy link
Contributor

@MWJeff MWJeff commented Aug 11, 2023

No description provided.

@carsonbot carsonbot added this to the 6.4 milestone Aug 11, 2023
@javiereguiluz
Copy link
Member

Thanks for this proposal. In my opinion, whether services are first or not, I think the most important is to be consistent and do always the same. I don't know if we're already using a standard practice in the code to put services first. We'll need to check what do we do. Thanks.

@HeahDude
Copy link
Contributor

Personally, I've always done (and encourage) the opposite: defining first route related arguments, then services used by the action.

However this does not work well with route related parameters that can be optional, since PHP 8.0 has deprecated defining optional arguments before required ones (https://www.php.net/manual/en/migration80.deprecated.php#migration80.deprecated.core).

So 👍 to make this the official recommendation.

@MWJeff
Copy link
Contributor Author

MWJeff commented Aug 11, 2023

@HeahDude This is also conform with PSR-12 : sometimes we defined optional query parameters :
"Method and function arguments with default values MUST go at the end of the argument list."
https://www.php-fig.org/psr/psr-12/#45-method-and-function-arguments

@javiereguiluz javiereguiluz requested a review from xabbuh as a code owner August 28, 2023 13:11
@javiereguiluz javiereguiluz force-pushed the improve-arguments-controller branch from f9487b7 to 951fc9b Compare August 28, 2023 13:11
@javiereguiluz javiereguiluz merged commit c9ecc7c into symfony:5.4 Aug 28, 2023
@javiereguiluz
Copy link
Member

This is now merged! @MWJeff thanks and congrats on your first Symfony Docs contribution 🎉

@seb-jean
Copy link
Contributor

seb-jean commented Sep 4, 2023

So, how will the arguments for the code below be sorted?

    #[Route('/{id}/like')]
    public function like(
        #[CurrentUser] User $user,
        User $liked,
        Request $request,
        EntityManagerInterface $entityManager
    ): Response {
        [...]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants