djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
401 stars 102 forks source link

Symfony.Commenting.FunctionComment.Missing not working for methods that use attributes #190

Open vpassapera opened 3 years ago

vpassapera commented 3 years ago

In my controller, I have:


    /**
     * Returns a single Feed Item.
     *
     * @OA\Tag(name="FeedItem")
     * @OA\Get(
     *     @OA\Parameter(
     *         name="uuid",
     *         in="path",
     *         description="UUID for the FeedItem",
     *         required=true,
     *         @OA\Schema(
     *              type="string"
     *         )
     *     ),
     *     @OA\Response(
     *         response=200,
     *         description="Returns a specific FeedItem by UUID.",
     *         @OA\MediaType(
     *             mediaType="application/json",
     *             @OA\Schema(ref=@Model(type=FeedItemResponse::class)),
     *         )
     *     ),
     *     @OA\Response(
     *         response=404,
     *         description="When the UUID is not found.",
     *     )
     * )
     *
     * @Security(name="None")
     *
     * @param string $uuid
     *
     * @return FeedItemResponse
     */
    #[Route('/{uuid}', name: 'get_feed_item', methods: ['GET'])]
    public function getFeedItem(string $uuid): FeedItemResponse
    {
        try {
            return $this->feedItemService->getFeedItemByUUID($uuid);
        } catch (NoResultException $e) {
            // Throw below...
        }

        throw $this->createNotFoundException(message: 'Feed item with that UUID was not found.', previous: $e);
    }

Running PHP CS on this, returns:

FILE: /shared/httpd/tcgtop8-api/src/Controller/FeedItemController.php                                     
------------------------------------------------------------------------------------------------------------                                                                                                         
FOUND 2 ERRORS AFFECTING 2 LINES                                                                                                                                                                                     
------------------------------------------------------------------------------------------------------------
 133 | ERROR | Missing doc comment for function getFeedItem()
     |       | (Symfony.Commenting.FunctionComment.Missing)   

It seems the sniff does not accept attributes in between the phpdoc block and the method. This seems incorrect.

It works if I move the attribute above the docblock, but that just seems lexically wrong.

mmoll commented 3 years ago

AFAICT, this is a problem in PHP CodeSniffer's PEAR.FunctionCommentSniff, which is only extended by Symfony.FunctionCommentSniff. Could anybody verify this and report it to the upstream project?

mmoll commented 3 years ago

https://github.com/squizlabs/PHP_CodeSniffer/pull/3396 might fix this.

mmoll commented 2 years ago

phpc 3.6.1 got released, @vpassapera could you test, if that fixes this issue?