How to check for syntax errors in Annotations?

We use API Platform , and this is a piece of code we pushed in production :

<?php

declare(strict_types=1);

namespace AppUtilityTotoAPIDTO;

/**
 * @ApiResource(
 *     shortName="Toto",
 *     normalizationContext={"groups"={"Toto:read"}},
 *     collectionOperations={
 *         "post"={
 *             "security_post_denormalize"="is_granted(
                    constant('AppUtilitySecurityRoleHierarchy::TOTO_WRITE'),
                    object
                )",
                "denormalization_context"={"groups"={"Toto:create"}}
 *         }
 *     },
 *     itemOperations={
 *         "get"={
 *             "security"="is_granted(
                    constant('AppUtilitySecurityRoleHierarchy::TOTO_READ'),
                    object
                )"
 *         },
 *         "put"={
 *              "security_post_denormalize"="is_granted(
 *                  constant('AppUtilitySecurityRoleHierarchy::TOTO_WRITE'),
 *                  object
 *              )",
 *              "denormalization_context"={"groups"={"Toto:update"}}
 *         },
 *     },
 *     subresourceOperations={
 *      "api_toto_get_subresource"={
 *          "security"="is_granted(constant('AppUtilitySecurityRoleHierarchy::TOTO_READ'), object)"
 *      }
 *    }
 * )
 */
class TotoApiDto
{

    ...

As you can see we had a syntax error where the * characters from the docblock were inserted in the is_granted() of the security_post_denormalize fuction of the put operation :


 *              "security_post_denormalize"="is_granted(
 *                  constant('AppUtilitySecurityRoleHierarchy::TOTO_WRITE'),
 *                  object
 *              )",

In the other functions above, we paid attention and didn’t include the * characters at the beginning of the lines inside the function.

How can I detect such issues in CI?

I tried to look for a linter or a PHPCS(Fixer) rule, but couldn’t find anything.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *