Ho un metodo che estrae un albero trasversale albero preordine modificato dal database, e filtri che utilizzano una funzione di callback. Per esempio:Come dovrei PHPDoc richiamare?
/**
* 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;
}
Non sono sicuro di quello che il PHPDoc dovrebbe essere per la variabile $filter
- è un callback, che è quello che ho indicato, ma non sono sicuro se questo è corretto.
Inoltre, ulteriori osservazioni sulla qualità (o la sua assenza) in questo codice sarebbe apprezzato :)
grande domanda. – zerkms