如何最好地为此函数编写注释,其中基于$data
参数类型的行为略有不同。
/**
* Appends data
*
* @param mixed - data array
* @param value
* @return self
*/
public function addData($data, $value = '')
{
if(is_array($data)){
$this->data = array_merge($this->data, $data);
} else {
if($value != ''){
$this->data[$data] = $value;
} else {
$this->data[] = $data;
}
}
return $this;
}
例子:
$this->addData($my_array);
$this->addData('my_var', $my_var);
$this->addData($my_var);
更新:
/**
* Appends data
*
* @param array|string - This can be either an array to be merged
* OR a value to be added to than array
* OR a key if the $value param is set.
* @param string - If set the first $data parma will be used as the key.
* @return object
*/