phpDocumentor How to document available options for string parameter

断了今生、忘了曾经 提交于 2019-12-05 02:50:28

问题


I have a public method for a class and I would like to document the available string values that the method can accept. Would this be acceptable:

/**
* Set size of photos
* 
* @param string $size can be one of these options: url_sq, url_t, url_s, url_m, url_o
* @return void
*/
public function setSize($size){
    $this->_size = $size;
}

回答1:


Yes, it's acceptable, but you can do it smarter:

class TheClass
{
 const photo_size_sq = 'url_sq';
 const photo_size_tiny = 'url_t';
 const photo_size_small = 'url_s';
 const photo_size_m = 'url_m';
 const photo_size_o = 'url_o';

/**
* Set size of photos
* 
* @param string $size see photo_size_* constants
* @return void
*/
public function setSize($size){
    $this->_size = $size;
}
}

So when you will call this function, you can use IDE's autocompletion, to not keep in memory all values and to be sure that your code typed correct, without typos:

$object->setSize($object::photo_size_small);

Of course, names of constants can be more short and more descriptive, when you are author of the code :)



来源:https://stackoverflow.com/questions/6476888/phpdocumentor-how-to-document-available-options-for-string-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!