[英]How to format PHPDoc comment for complex return values
我有一個函數,它返回類似以下結構的內容:
array('form' => $form, 'options' => $options)
如何在函數注釋中正確設置此返回值的格式?
我的猜測是:
@return array('form' => CForm, 'options' => array) ... comment ...
有什么建議么?
當您必須返回一個怪異的數組時,請對其進行記錄,既簡單又易於理解。
這就是我要做的。 隨意使用@return array
而不使用mixed[]
:
<?php
/**
* Method to do something
*
* @param Some_User_Class $user
* @param string $blockUserId
* @throws Some_Model_Relations_ErrorException
* @return mixed[] see example
* @example The returned array consists of this
* and that and might have foo and bar.
* so this makes me feel like the code should be refactored.
*/
public function unblockUser(Some_User_Class $user, $unblockUserId) {
}
也許有些矯kill過正,但是您可以返回具有特定接口的對象,而不是常規數組。 就像是:
/**
* @return ReturnObject
*/
public function yourMethod()
{
return new ReturnObjectImpl( $theForm, $theOptions );
}
interface ReturnObject
{
public function getCForm();
public function getOptions();
}
class ReturnObjectImpl
implements ReturnObject
{
protected $_form;
protected $_options;
public function __construct( CForm $form, array $options )
{
$this->_form = $form;
$this->_options = $options;
}
public function getCForm()
{
return $this->_form;
}
public function getOptions()
{
return $this->_options;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.