PHPDocumentor 注释规范整理

20 篇文章 0 订阅

 你会写注释么?从我写代码开始,这个问题就一直困扰着我,相信也同样困扰着其他同学。以前的写注释总是没有一套行之有效的标准,给维护和协同开发带了许多麻烦,直到最近读到了phpdocumentor的注释标准。

 

下面对phpdocumentor的注释标准进行总结:


Type(数据类型):

 

  1. string 字符串类型
  2. integer or int 整型
  3. boolean or bool 布尔类型 true or false
  4. float or double 浮点类型
  5. object 对象
  6. mixed 混合类型 没有指定类型或不确定类型时使用
  7. array 数组
  8. resource 资源类型 (如数据库查询返回)
  9. void 空值(控制器返回值经常使用)
  10. null null类型
  11. callable 回调函数
  12. false or true 只返回true or fasle 时使用
  13. self 自身

 

Tags(标签):

 

Tag

Element

Description

api

Methods

声明接口

author

Any

作者信息

category

File, Class

将一系列的元素分类在一起

copyright

Any

版权信息

deprecated

Any

声明元素已被弃用,可以在将来的版本中删除

example

Any

示例

filesource

File

文件资源

global

Variable

声明一个全集变量

ignore

Any

忽略当前元素 phpdocumentor 生成文档时)

internal

Any

声明一个值为整形,或者设置一个应用的默认值为整型

license

File, Class

声明许可类型

link

Any

声明一个和当前元素有关的链接

method

Class

声明当前类那些魔术方法可以被调用

package

File, Class

声明当前元素所属的包

param

Method, Function

声明当前元素的一个参数

property

Class

声明当前类有那些魔术方法可以被调用属性

property-read

Class

声明当前类有那些魔术方法可以读取属性

property-write

Class

声明当前类有那些魔术方法可以设置属性

return

Method, Function

返回值

see

Any

说明当前元素参数引用于其他站点或元素

since

Any

声明当前元素始于于哪个版本

source

Any, except File

展示当前元素的源码

subpackage

File, Class

将当期元素分类

throws

Method, Function

说明当前元素抛出的异常

todo

Any

说明当前元素的开发活动

uses

Any

引用一个关联元素

var

Properties

 声明属性

version

Any

版本

 

 

Example(示例):

 

// =============================

 

@api

 

[php]  view plain  copy
  1. /** 
  2.   * This method will not change until a major release. 
  3.   * 
  4.   * @api 
  5.   * 
  6.   * @return void 
  7.   */  
  8.   function showVersion()  
  9.   {  
  10.      <...>  
  11.   }  

// =============================

 

@author

 

[php]  view plain  copy
  1. /** 
  2.   * @author My Name 
  3.   * @author My Name <my.name@example.com> 
  4.   */  

 

// =============================

 

@category

 

[php]  view plain  copy
  1. /** 
  2.  * Page-Level DocBlock 
  3.  * 
  4.  * @category MyCategory 
  5.  * @package  MyPackage 
  6.  */  

 

// =============================

 

@copyright

 

[php]  view plain  copy
  1. /** 
  2.   * @copyright 1997-2005 The PHP Group 
  3.   */  

 

// =============================

 

@deprecated

 

[php]  view plain  copy
  1. /** 
  2.   * @deprecated 
  3.   * @deprecated 1.0.0 
  4.   * @deprecated No longer used by internal code and not recommended. 
  5.   * @deprecated 1.0.0 No longer used by internal code and not recommended. 
  6.   */  
  7.  function count()  
  8.  {  
  9.      <...>  
  10.  }  

 

// =============================

 

@example

 

[php]  view plain  copy
  1. /** 
  2.   * @example example1.php Counting in action. 
  3.   * @example http://example.com/example2.phps Counting in action by a 3rd party. 
  4.   * @example "My Own Example.php" My counting. 
  5.   */  
  6.  function count()  
  7.  {  
  8.      <...>  
  9.  }  

 

// =============================

 

@filesource

 

[php]  view plain  copy
  1. /** 
  2.   * @filesource 
  3.   */  

 

// =============================

 

@global phpdocumentor2.0不支持

 

// =============================

 

@ignore

 

[php]  view plain  copy
  1. if ($ostest) {  
  2.      /** 
  3.       * This define will either be 'Unix' or 'Windows' 
  4.       */  
  5.      define("OS","Unix");  
  6.  } else {  
  7.      /** 
  8.       * @ignore 
  9.       */  
  10.      define("OS","Windows");  
  11.  }  

 

// =============================

 

@internal

 

[php]  view plain  copy
  1. /** 
  2.  * @internal 
  3.  * 
  4.  * @return integer Indicates the number of items. 
  5.  */  
  6. function count()  
  7. {  
  8.     <...>  
  9. }  

 

[php]  view plain  copy
  1. /** 
  2.  * Counts the number of Foo. 
  3.  * 
  4.  * {@internal Silently adds one extra Foo to compensate for lack of Foo }} 
  5.  * 
  6.  * @return integer Indicates the number of items. 
  7.  */  
  8. function count()  
  9. {  
  10.     <...>  
  11. }  

 

// =============================

 

@license

 

[php]  view plain  copy
  1. /** 
  2.   * @license GPL 
  3.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
  4.   */  

 

// =============================

 

@link

 

[php]  view plain  copy
  1. /** 
  2.   * @link http://example.com/my/bar Documentation of Foo. 
  3.   * 
  4.   * @return integer Indicates the number of items. 
  5.   */  
  6.  function count()  
  7.  {  
  8.      <...>  
  9.  }  

 

[php]  view plain  copy
  1. /** 
  2.   * This method counts the occurrences of Foo. 
  3.   * 
  4.   * When no more Foo ({@link http://example.com/my/bar}) are given this 
  5.   * function will add one as there must always be one Foo. 
  6.   * 
  7.   * @return integer Indicates the number of items. 
  8.   */  
  9.  function count()  
  10.  {  
  11.      <...>  
  12.  }  

 

// =============================

 

@method

 

[php]  view plain  copy
  1. class Parent  
  2.  {  
  3.      public function __call()  
  4.      {  
  5.          <...>  
  6.      }  
  7.  }  
  8.    
  9.  /** 
  10.   * @method string getString() 
  11.   * @method void setInteger(integer $integer) 
  12.   * @method setString(integer $integer) 
  13.   */  
  14.  class Child extends Parent  
  15.  {  
  16.      <...>  
  17.  }  

 

// =============================

 

@package

 

[php]  view plain  copy
  1. /** 
  2.   * @package PSR\Documentation\API 
  3.   */  

 

// =============================

 

@param

 

[php]  view plain  copy
  1. /** 
  2.   * Counts the number of items in the provided array. 
  3.   * 
  4.   * @param mixed[] $items Array structure to count the elements of. 
  5.   * 
  6.   * @return int Returns the number of elements. 
  7.   */  
  8.  function count(array $items)  
  9.  {  
  10.      <...>  
  11.  }  

 

// =============================

 

@property

 

[php]  view plain  copy
  1. class Parent  
  2.  {  
  3.      public function __get()  
  4.      {  
  5.          <...>  
  6.      }  
  7.  }  
  8.    
  9.  /** 
  10.   * @property string $myProperty 
  11.   */  
  12.  class Child extends Parent  
  13.  {  
  14.      <...>  
  15.  }  

 

// =============================

 

@property-read

 

[php]  view plain  copy
  1. class Parent  
  2.  {  
  3.      public function __get()  
  4.      {  
  5.          <...>  
  6.      }  
  7.  }  
  8.    
  9.  /** 
  10.   * @property-read string $myProperty 
  11.   */  
  12.  class Child extends Parent  
  13.  {  
  14.      <...>  
  15.  }  

 

// =============================

 

@property-write

 

[php]  view plain  copy
  1. class Parent  
  2. {  
  3.     public function __set()  
  4.     {  
  5.         <...>  
  6.     }  
  7. }  
  8.   
  9. /** 
  10.  * @property-write string $myProperty 
  11.  */  
  12. class Child extends Parent  
  13. {  
  14.     <...>  
  15. }  

 

// =============================

 

@return

 

[php]  view plain  copy
  1. /** 
  2.   * @return integer Indicates the number of items. 
  3.   */  
  4.  function count()  
  5.  {  
  6.      <...>  
  7.  }  

[php]  view plain  copy
  1. /** 
  2.   * @return string|null The label's text or null if none provided. 
  3.   */  
  4.  function getLabel()  
  5.  {  
  6.      <...>  
  7.  }  

 

// =============================

 

@see

 

[php]  view plain  copy
  1. /** 
  2.  * @see http://example.com/my/bar Documentation of Foo. 
  3.  * @see MyClass::$items           for the property whose items are counted 
  4.  * @see MyClass::setItems()       to set the items for this collection. 
  5.  * 
  6.  * @return integer Indicates the number of items. 
  7.  */  
  8. function count()  
  9. {  
  10.     <...>  
  11. }  

 

// =============================

 

@since

 

[php]  view plain  copy
  1. /** 
  2.   * @since 1.0.1 First time this was introduced. 
  3.   * 
  4.   * @return integer Indicates the number of items. 
  5.   */  
  6.  function count()  
  7.  {  
  8.      <...>  
  9.  }  

 

[php]  view plain  copy
  1. /** 
  2.  * @since 1.0.2 Added the $b argument. 
  3.  * @since 1.0.1 Added the $a argument. 
  4.  * @since 1.0.0 
  5.  * 
  6.  * @return void 
  7.  */  
  8. function dump($a$b)  
  9. {  
  10.     <...>  
  11. }  

 

// =============================

 

@source

 

[php]  view plain  copy
  1. /** 
  2.   * @source 2 1 Check that ensures lazy counting. 
  3.   */  
  4.  function count()  
  5.  {  
  6.      if (null === $this->count) {  
  7.          <...>  
  8.      }  
  9.  }  

 

// =============================

 

@subpackage

 

[php]  view plain  copy
  1. /** 
  2.   * @package PSR 
  3.   * @subpackage Documentation\API 
  4.   */  

 

// =============================

 

@throws

 

[php]  view plain  copy
  1. /** 
  2.   * Counts the number of items in the provided array. 
  3.   * 
  4.   * @param mixed[] $array Array structure to count the elements of. 
  5.   * 
  6.   * @throws InvalidArgumentException if the provided argument is not of type 
  7.   *     'array'. 
  8.   * 
  9.   * @return int Returns the number of elements. 
  10.   */  
  11.  function count($items)  
  12.  {  
  13.      <...>  
  14.  }  


// =============================

 

@todo

 

[php]  view plain  copy
  1. /** 
  2.  * Counts the number of items in the provided array. 
  3.  * 
  4.  * @todo add an array parameter to count 
  5.  * 
  6.  * @return int Returns the number of elements. 
  7.  */  
  8. function count()  
  9. {  
  10.     <...>  
  11. }  

 

// =============================

 

@uses

 

[php]  view plain  copy
  1. /** 
  2.   * @uses MyClass::$items to retrieve the count from. 
  3.   * 
  4.   * @return integer Indicates the number of items. 
  5.   */  
  6.  function count()  
  7.  {  
  8.      <...>  
  9.  }  

 

// =============================

 

@var

 

[php]  view plain  copy
  1.  class Counter  
  2.  {  
  3. /** 
  4.   * @var 
  5.   */  
  6. public $var;  
  7.  }  

 

// =============================

 

@version

 

[php]  view plain  copy
  1. /** 
  2.   * @version 1.0.1 
  3.   */  
  4.  class Counter  
  5.  {  
  6.      <...>  
  7.  }  

 

[php]  view plain  copy
  1. /** 
  2.  * @version GIT: $Id$ In development. Very unstable. 
  3.  */  
  4. class NeoCounter  
  5. {  
  6.     <...>  
  7. }  

 

// =============================

 

phpdocumentor手册:http://www.phpdoc.org/docs/latest/index.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值