phpstormapache-velocity

Check if variable is empty in PhpStorm file template


I'm trying to follow Zend coding standard for comments blocks for functions and I've stuck during PHP Function Doc Commentcustomization.

This is my current code look

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

The assumption for this is that it should add an asterisk only if ${PARAM_DOC} is not nullable, but this code doesn't work. It always adds an asterisk. The documentation of PhpStorm Variables doesn't contain any useful informations for my problem so I hope that somebody here can help me.

My PhpStorm version is 2019.3 EAP.


Solution

  • As the build-in PhpStorm for ${PARAM_DOC} description says

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

    And Apache Velocity docs says

    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.

    After that I understood that I'm making one important mistake. PhpStorm is based on Java and an empty String cant be automatically casted to Boolean beacuse ${PARAM_DOC} is just a Java String.

    So solution for that turned out to be

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

    Obvious but not quiet.