检查 PhpStorm 文件模板中的变量是否为空

Check if variable is empty in PhpStorm file template

我正在尝试遵循 Zend 函数注释块的编码标准,但我在 PHP Function Doc Comment 自定义过程中卡住了。

这是我当前的代码外观

/**
${PARAM_DOC}
#if(${PARAM_DOC})
 *
#end
 * @return ${TYPE_HINT}
${THROWS_DOC}
*/

对此的假设是仅当 ${PARAM_DOC} 不可为空时才应添加星号,但此代码不起作用。它总是添加一个星号。 PhpStorm 变量的文档不包含任何对我的问题有用的信息,所以我希望这里有人可以帮助我。

我的PhpStorm版本是2019.3 EAP。

正如 ${PARAM_DOC} 的内置 PhpStorm 描述

Parameters' doc comment. Generated as a number of lines '* @param type name". If there are no parameters, evaluates to an empty content.

Apache Velocity 文档说

When VTL references a variable, such as $foo, the variable can get its value from either a set directive in the template, or from the Java code.

之后我明白我犯了一个重要的错误。 PhpStorm 基于 Java 并且空 String 不能自动转换为 Boolean 因为 ${PARAM_DOC} 只是一个 Java 字符串

所以解决方案是

#if (${PARAM_DOC} != "")
 *
#end

明显但不安静。