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

如何在PhpStorm 8中创建新的phpDoc注释,phpstorm,phpdoc,Phpstorm,Phpdoc,我通过谷歌搜索,但找不到答案。PhpStorm有许多用于代码完成的内置注释,但也有许多注释缺失。我很确定有一种方法可以创建新的注释,但在设置中的任何地方都找不到。或者它可能是某个XML文件。NetBeans支持此功能 换句话说,我如何创建新的phpDoc注释以在phpStorm 8中完成,如phpUnit的@usesDefaultClass。我在这里找到了这个答案: 希望这对你有帮助 PhpDoc模板 PhpDoc模板位于“设置|文件模板|包含”下。目前有三个模板,分别是PHP类Doc Comm

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


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

我在这里找到了这个答案: 希望这对你有帮助

PhpDoc模板

PhpDoc模板位于“设置|文件模板|包含”下。目前有三个模板,分别是PHP类Doc Comment、PHP函数Doc Comment和PHP字段Doc Comment。其中任何一个都可以通过#parse指令包含到其他模板中。例如,我们可以修改原始类模板(Templates | PHP类),以便在生成类时也包含类PHP文档:

<?php
#parse("PHP File Header.php")
...
#parse("PHP Class Doc Comment")
class ${NAME} {
}
  • @参数$x
  • @参数$y

    ${u DOC}

    生成的PHP文档片段包含从函数(方法)体抛出的异常,格式为
    *@throws ExceptionName
    。每行/@throws标记一个异常。例如:

    • @例外
    • @抛出HttpException
重写/实现方法的代码模板

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

美元符号变量:
${DS}


解决了在模板中的任意位置放置美元符号$的问题。实际上,美元符号在PHP和Velocity模板引擎中都使用,负责幕后的代码生成。因此,每当我们需要一个美元符号时,只要使用
${DS}
作为它的等价物。例如,如果我们想要生成
$this->foo()
,我们需要将
${DS}this->foo()
。这看起来可能不完美,但可以保证不会有冲突。

感谢您提供了详尽的答案,但问题是关于phpDoc注释/标记完成,而不是PhpStorm中的模板。我认为您可以使用自定义模板来实现这一点,但您可以使用此插件来实现。我认为:自定义注释是一项任务,看来在phpStorm中根本不可能(什么是
@usesDefaultClass
@使用的
是phpUnit中的一个新注释,用于指示将在严格模式下调用此方法但未进行测试的代码覆盖率收集器。
@usesDefaultClass
用于指定所有
@使用的
注释所引用的类的完整类名。)(除非它们有完整的名称空间)。我不明白的是,“创建新的phpDoc注释以完成”到底是什么意思?--帮助IDE完成@tag..,或者让标记后面的文本作为类名,这样IDE帮助完成类名..或者什么?在任何情况下:标记列表和特定位置都不能从外部来源告知IDE--例如“支持”必须进行硬编码。因此,请在Issue Tracker中提交一个新的票证,这两个网站都会很好,并且NetBeans支持此功能,因此我认为PhpStorm也支持此功能。我将为它创建一个票证,因为它需要编码。将您的评论作为答案发布,我将接受它作为正确的答案。它到底支持什么?有吗示例?NetBeans如何知道new@tag,以及在它后面应该有类名?
${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:
${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.