False positive of duplicate lines for PHP Symfony Attributes

Hi,

SonarCloud marks a lot of duplicate lines for attributes. For instance describing Api Controllers.

Is there a way to exclude these lines?

    #[Route(
        path: '/v1/infocontroller/{id}',
        name: 'info',
        requirements: ["id"=>"\d+"],
        methods: ['GET']
    )]
    #[OA\Get(operationId: 'getInfo')]
    #[OA\Parameter(
        name: 'id',
        description: 'The id',
        in: 'path',
        required: true,
        schema: new OA\Schema(type: 'integer', minimum: 1, example: 1)
    )]
    #[OA\Response(
        response: Response::HTTP_OK,
        description: 'Returns the info',
        content: new OA\JsonContent(
            ref: new DOCA\Model(type: InfoModel::class))
    )]
    #[OA\Response(
        response: Response::HTTP_NOT_FOUND,
        description: 'Info not found'
    )]

Thanks,
Arjan Vermunt

Hello @ArieGato and welcome on Community!

Sorry for the late reply, we are investigating your issue and will come back to you soon.

Best,

Hello @ArieGato,

From my understanding, this duplicate line detection is working as expected, as you have very similar/identical lines of codes in different files, which describe your Api Controllers.
Is that correct?

I checked, and currently, it is impossible to exclude a specific set of lines in SonarCloud.
It is only possible to exclude files or even packages; you can do this by adding this property to your scanner configuration:

sonar.cpd.exclusions=path/to/your/package/*.php

Analysis Scope | SonarCloud (“Scope of duplication detection” chapter)

I hope that help.
Best,

Edit: After an internal discussion, we decided it would make sense to globally exclude the PHP attribute group from the duplicate mechanism.

This has been integrated on our side and should be available soon on SonarCloud.

Thnx @rudy.regazzoni,

I can’t wait for the fix. Sorry for the late reaction.

Kind regards,
Arjan