How to automatically format PHP annotations in PHPStorm
Asked Answered
W

1

9

I'm working with a large number of files that have PHP block docs with Swagger PHP annotations on them, however they are not indented. Is there anyway to automatically format them with spaces?

Turning

/**
 * @SWG\Api(
 * path="/building/{buildingId}",
 * @SWG\Operation(
 * method="GET",
 * type="Building",
 * summary="Returns a Building object by ID",
 * nickname="building/getBuilding",
 * @SWG\Parameter(
 * name="buildingId",
 * description="ID of the building that needs to be fetched",
 * paramType="path",
 * required=false,
 * type="string",
 * defaultValue="1"
 * )
 * )
 * )
 */

Into

/**
 * @SWG\Api(
 *   path="/building/{buildingId}",
 *   @SWG\Operation(
 *     method="GET",
 *     type="Building",
 *     summary="Returns a Building object by ID",
 *     nickname="building/getBuilding",
 *     @SWG\Parameter(
 *       name="buildingId",
 *       description="ID of the building that needs to be fetched",
 *       paramType="path",
 *       required=false,
 *       type="string",
 *       defaultValue="1"
 *     )
 *   )
 * )
 */
Wolff answered 11/6, 2015 at 17:21 Comment(1)
AFAIK no because it was requested long time ago to not to touch such annotations at all, e.g. youtrack.jetbrains.com/issue/WI-10053 . But then -- I'm not suing such annotations myself and therefore could be wrong here.Removable
W
6

Looking into this unfortunately there isn't anything built into PHPStorm to do this. I fixed this issue with a bit of node and have open sourced my work if anyone else needs it.

:)

https://github.com/eknowles/grunt-tidy-annotations

Wolff answered 13/6, 2015 at 15:30 Comment(3)
Is this solution still working? I've tried it but it doesn't format the Swagger annotations. Is there some native support in PHPStorm for formatting Swagger annotations by now?Carlotacarlotta
Unfortunately wasn't working anymore, not for new versions of swagger and PHPStorm doesn't have a native support do Swagger annotations as far I know.Midsummer
This doesn't work anymore, sad that Jetbrains can't implement these simple formatting features.Fuller

© 2022 - 2024 — McMap. All rights reserved.