记录 PHP,如果我扩展一个类,我应该复制/粘贴吗?
我有一个带有方法的 PHP 类。在基类中(它更像是原型,但我没有使用原型,因为我们必须向后兼容),我记录了方法的参数和描述。
现在我延长该课程。在这个新方法(实现)中,我应该重新记录参数和描述,应该将其留空,还是应该只留下适用于该特定实现的相关注释?
我的目标是拥有由 PhpDoc 生成的可读 API 文档,并遵循约定。
I have a PHP class with a method. In the base class (it's more like a prototype, but I'm not using prototypes because we have to be backwards compatible), I document the parameters and description of the method.
Now I extend that class. In this new method (the implementation) should I re-document the parameters and description, should I leave it blank, or should I only leave relevant notes that apply to that particular implementation?
My goal is to have readable API docs produced by PhpDoc, and to follow conventions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PhpDocumentor 将向您显示正在记录的方法是否是父类中该方法的重新定义以及该方法是否在子类中被重写。因此,除了您放入方法文档块中的所有信息之外,您还将看到有一个与当前方法关联的父方法和/或子方法。这意味着在方法的文档块中说某些内容对您有利。
我倾向于做的是将关键通用语言向上浮动到父方法,但我仍然对当前子方法以及孙方法有话要说。无论子方法与父方法有何不同,和/或该子方法与来自同一父方法的其他子方法的不同之处,都是该子方法文档块所需的信息。
我永远不会将父母的某些东西复制/粘贴到孩子身上......相反,我将进一步澄清是什么让孩子成为他的父母和/或他的兄弟姐妹。另外,我尝试不谈论父文档块内的子元素,因为典型的父子关系是作为一种抽象方式来消除需要了解子元素的具体情况的。
PhpDocumentor is going to show you if the method being documented is a redefinition of the method in a parent class as well as if the method gets overridden in a child class. So, in addition to all info that you put in the method's docblock, you will also see that there is a parent method and/or child method associated to the current method. This means it is to your benefit to say something in the method's docblock.
What I tend to do is to float the key generic language upwards toward the parent method, but I'll still have something to say about the current child's method as well as a grandchild's method. Whatever differentiates the child method from the parent method, and/or whatever differentiates this child method from other child methods that are its peers from the same parent, is the info needed by this child method docblock.
I'm never going to copy/paste something from a parent to a child... I'm instead going to further clarify what makes the child who he is with regard to his parent and/or his siblings. Also, I try not to say anything about the children inside the parent's docblock, since the typical parent-child relationship is done as a way to abstract away needing to know the specifics of the children.
查看 Zend Framework 中的几个示例,似乎注释大多是复制粘贴的——这有时会导致不同的注释。
我将采用的第一个示例是 Zend_Http_Client_Adapter_Interface::connect,它被声明为:
并且,如果您看一下实现此接口的类,例如
Zend_Http_Client_Adapter_Curl
,你会看到:所以,复制粘贴参数;以及实施中的更多信息。
另一个例子是
Zend_Log_Writer_Abstract::_write
:并且,在子类中,如
Zend_Log_Writer_Db
:这里,再次复制粘贴;以及父类中的一个小修改,该修改尚未在子类中重新创建。
现在,我一般做什么?
Looking at a couple of examples in Zend Framework, it seems the comments are mostly copy-pasted -- and this sometimes leads to different comments.
The first example I'll take is
Zend_Http_Client_Adapter_Interface::connect
, which is declared as :And, if you take a look at a class that implements this interface, like
Zend_Http_Client_Adapter_Curl
, you'll see :So, copy-paste of the parameters ; and more informations in the implementation.
Another example would be
Zend_Log_Writer_Abstract::_write
:And, in a child class, like
Zend_Log_Writer_Db
:Here, again, copy-paste ; and a small modification in the parent class, that has not been re-created in the child class.
Now, what do I generally do ?