PhpStorm函数注释的设置
一、总结
一句话总结:
添加模板 添加变量
应用变量
a、添加模板,添加變量,在(PhpStorm中setting-》Editor-》LiveTemplate)中添加模板添加變量
$DATE$ $TIME$
b、應用變量,在(setting-》Editor-》FIle and Code Template-》Includes)中應用變量
/*** Notes:* User: ${USER}* Date: ${DATE}* Time: ${TIME}${PARAM_DOC}#if (${TYPE_HINT} != "void") * @return ${TYPE_HINT}#end${THROWS_DOC}*/
1、phpstorm中如何给方法函数添加注释?
在方法前面,输入/**后回车
2、方法(函数)注释样例?
/*** Notes:* User: ${USER}* Date: ${DATE}* Time: ${TIME}${PARAM_DOC}#if (${TYPE_HINT} != "void") * @return ${TYPE_HINT}#end${THROWS_DOC}*/
应用这样样例得到的注释结果:
/*** Notes:* User: rfan* Date: -11-04* Time: 7:13 AM* @param $param1* @param $param2* @param $param3* @return \think\response\View|void* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\ModelNotFoundException* @throws \think\exception\DbException*/
3、我们想设置各种模板样例在哪里设置,比如html文件的默认代码,比如类、方法等的注释?
setting editor templates
File->Setting->Editor->File and Code Templates
二、PhpStorm函数注释的设置
首先,PhpStorm中文件、类、函数等注释的设置在:setting-》Editor-》FIle and Code Template-》Includes下设置即可,其中方法的默认是这样的:
/**${PARAM_DOC}#if (${TYPE_HINT} != "void") * @return ${TYPE_HINT}#end${THROWS_DOC}*/
但是我发现,文件中的默认注释是这样的:
1 /**2 * Created by ${PRODUCT_NAME}.3 * User: ${USER}4 * Date: ${DATE}5 * Time: ${TIME}6 */
当我把上面这段中3、4、5行的代码直接复制放到PHP Function Doc Comment这个下面的时候,发现其中占位符{}中的东西并没有被替换,而是当成字符串打出来了。
方法:
1、我们在PhpStorm中setting-》Editor-》LiveTemplate,即找到模板选项,会看到各种语言的模板设置;
2、找到右边有个+号,创建一个自定义模板:选择LiveTemplate,然后按照下图的配置顺序进行设置:
3、点保存之后,回到FIle and Code Template-》Includes,在PHP Function Doc Comment这里设置:
/*** Notes:* User: ${USER}* Date: ${DATE}* Time: ${TIME}${PARAM_DOC}#if (${TYPE_HINT} != "void") * @return ${TYPE_HINT}#end${THROWS_DOC}*/
4、点击Apply,点击OK,然后在方法前面,输入/**后回车:
/*** Notes:下单接口* User: Steven* Date: /12/28* Time: 15:19* @return array* @throws \yii\db\Exception*/
OK,完成。
參考:PhpStorm函数注释的设置 - Steven* - 博客园
/Steven-shi/p/8136081.html