如何在PhpStorm 8中创建新的phpDoc注释

时间:2014-11-18 17:54:04

标签: phpstorm phpdoc

我通过Google搜索但无法找到答案。 PhpStorm有很多内置的代码完成注释,但很多都缺失了。我很确定有一种方法可以创建新的注释,但无法在设置中的任何位置找到它。或者它可能是某个地方的XML文件。 NetBeans支持此功能。

换句话说,如何在phpStorm 8中为phpUnit创建新的phpDoc注释,如@usesDefaultClass

1 个答案:

答案 0 :(得分:0)

我在这里找到了这个答案:http://blog.jetbrains.com/webide/2013/02/phpdoc_and_code_templates/ 希望这会对你有所帮助

PhpDoc模板

PhpDoc模板位于“设置”下文件模板|包括。目前有三个模板名为PHP Class Doc Comment,PHP Function Doc Comment和PHP Field Doc Comment。其中任何一个都可以通过#parse指令包含在其他模板中。例如,我们可以修改原始类模板(Templates | PHP Class),以便在生成类时包含PHP Doc类:

<?php
#parse("PHP File Header.php")
...
#parse("PHP Class Doc Comment")
class ${NAME} {
}

在以下情况下使用相同的模板:

在输入/ **之后生成一个新的PHP Doc注释,并在类,函数(方法)或类字段之前按Enter键。 我们调用Code |生成| PHPDoc阻止或使用Add PHP Doc快速修复程序检查缺少PHP文档。 下面是可以在PHP Doc模板中使用的变量列表:

${NAME}

The element (class, function, field) name.
${NAMESPACE}

The name of the namespace the element belongs to without any leading or trailing backslashes, for example Core\Widgets. The variable value is empty if the element doesn’t belong to any namespace. A check like `#if (${NAMESPACE})` ... is possible.
${CLASS_NAME}

Contains a class name for class methods and fields. Will be empty for functions that do not belong to any class.
${TYPE_HINT}

For functions (methods), contains the return type of the function (method). For fields, evaluates to the field’s type if it can be found, for example, from a default value. Will be empty if the type cannot be retrieved from the code.
${STATIC}

Takes the value of “static” if the function or field is static, otherwise, an empty string. We can use this variable with the condition `#if (${STATIC})` ... to generate something specific for static class members.
${CARET}

Marks the position where the editor caret should be placed after the comment is added. Note: Works only if the comment is added after we type “/**” and hit Enter. Should be placed inside the comment, not on the first line /** or on the last line */. In all other cases the caret marker will be ignored.
${PARAM_DOC}

A generated PHP Doc fragment containing function (method) parameters in the form: “* @param type $name“. For example, if the function signature is foo ($x, $y), it will evaluate to:
  • @param $ x
  • @param $ y

    $ {THROWS_DOC}

    生成的PHP Doc片段,其中包含以* @throws ExceptionName形式从函数(方法)主体抛出的异常。每行/ @ throws标记有一个例外。例如:

    • @throws DOMException
    • @throws HttpException

重写/实施方法的代码模板

可在设置|下找到以下模板文件模板|代码:PHP实现了方法体和PHP重写方法体。参数很少,考虑到在大多数情况下我们需要简单调用父方法或者只需要我们自己的注释(可能是某些版本的TODO):

${NAME}

Method name.
${PARAM_LIST}

A comma-separated list of parameters. For example, if the original method signature is foo(Bar $bar, $y), the variable will take the value “$bar, $x” which can be used in a call to the parent method as `${NAME}(${PARAM_LIST})`”
${RETURN}

Either “return” or an empty string.

美元符号变量:${DS}

解决在模板中的任何位置放置美元符号$的问题。实际上,美元符号既可以在PHP中使用,也可以在Velocity模板引擎中使用,可以在后台处理代码生成。因此,每当我们需要美元符号时,只需使用${DS}作为等价物。例如,如果我们想要生成$this->foo(),我们需要放置${DS}this->foo()。这看起来可能并不完美但保证不存在冲突。