Ignore Code Coverage for PHP Attributes?

We are using PHP and Sonar is reporting PHP attributes as uncovered code. To be specific this is an attribute used to describe OpenAPI spec that is then generated based on the attributes.

I know you can exclude rules, but how do we make Sonar ignore only parts of a file coverage?

How can we exclude them from being detected as untested code?

Version: Sonarqube Server Community Version v10.7 (96327)
Deployment: Docker on AWS ECS

Example of the attributes:

    #[OA\Post(
        operationId: 'post-filter-view',
        description: 'xxxxx',
        summary: 'Filter View',
        tags: ['Filter'],
        parameters: [
            new OA\Parameter(
                name: 'type',
                in: 'path',
                required: true,
                schema: new OA\Schema(type: 'string', enum: ['xxx', 'xxx'])
            ),
            #new OA\Parameter(ref: './Parameters.yaml#/page'),
            #new OA\Parameter(ref: './Parameters.yaml#/page_size'),
        ],
        requestBody: new OA\RequestBody(
            description: 'Applied filters',
            content: new OA\MediaType(
                mediaType: 'application/json',
                schema: new OA\Schema(
                    type: 'array',
                    items: new OA\Items(ref: '#/components/schemas/AppliedFilter')
                )
            )
        ),
        responses: [
            new OA\Response(
                response: 200,
                description: 'OK',
                content: new OA\MediaType(
                    mediaType: 'application/json',
                    schema: new OA\Schema(
                        type: 'array',
                        items: new OA\Items(
                            anyOf: [
                            ]
                        )
                    )
                )
            ),
        ]
    )]

Hey there.

SonarQube relies on the test coverage report to state which code can be covered by tests.

I think your ultimate goal is to have this PHPUnit ticket resolved to ignore attribute declarations.

In the meantime, you should be able to use PHPUnit’s own mechanisms for ignoring code blocks, which will be reflected in SonarQube when uploading the report.

You can also use PHPUnit’s