如何在 PHPStorm 中自动格式化 PHP 注释

How to automatically format PHP annotations in PHPStorm

我正在处理大量文件,这些文件具有 PHP 带有 Swagger PHP 注释的块文档,但它们没有缩进。反正有没有自动用空格格式化它们?

转向

/**
 * @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"
 * )
 * )
 * )
 */

进入

/**
 * @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"
 *     )
 *   )
 * )
 */

不幸的是,PHPStorm 中没有内置任何东西来执行此操作。我用一些节点解决了这个问题,如果其他人需要它,我已经开源了我的工作。

:)

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