我应该如何 PHPDoc 进行回调?
我有一个方法,从数据库中提取修改后的预序树横向树,并使用回调函数进行过滤。例如:
/**
* Recursive function for building the Cas_Template_TreeNode.
*
* @static
* @param array $rows
* @param callback $filter A function to filter the tree by (return a value convertible to false to remove the item from the tree)
* @return array
*/
private static function MakeTreeGivenDbRows($rows, $filter = null)
{
if ($filter === null)
{
$filter = function($unused)
{
return true;
};
}
$result = array();
$childrenCount = 0;
for ($idx = 0; $idx < count($rows); $idx += $childrenCount + 1)
{
$current = $rows[$idx];
$childrenCount = self::ChildrenCountFromRow($current);
if (!$filter($current))
{
continue;
}
$childrenStartAt = $idx + 1;
$childRows = array_slice($rows, $childrenStartAt, $childrenCount);
$children = self::MakeTreeGivenDbRows($childRows, $filter);
$result[] = new Cas_Template_TreeNode(self::MakeNodeGivenDbRow($current), $children);
}
if (empty($result))
{
return null;
}
return $result;
}
我不确定变量的PHPDoc应该是什么 - 它是一个回调,这就是我所指出的,但我不确定这是否正确。$filter
此外,对本代码中的质量(或缺乏质量)的任何其他评论将不胜感激,:)