Optional arguments to PHPDocumentor

I am trying to write a phpdocumentor block for the following:

/** * daysBetween * * Returns the number of whole working days between start_date and end_date. Working * days exclude weekends and any dates identified in holidays. * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of * days worked during a specific term. * * @param DateTime $startDate Start date * @param DateTime $endDate End date * @param DateTime $holidays,... Optional series of dates that will be excluded * @return integer Interval between the dates */ public function daysBetween($startDate,$endDate) { // Shift the mandatory start and end date that are referenced // in the function definition, to get any optional days $holidays = func_get_args(); array_shift($holidays); array_shift($holidays); 

$ startDate and $ endDate are mandatory arguments, while all instances of $ holidays are optional ... there cannot be one, not one, or several given vacation days. The definition of PHPDocumentor above gives me

Parameter $ holidays, ... not found in daysBetween ()

I believe that it is possible to get around this by changing the definition of the method to

 public function daysBetween($startDate,$endDate,$holidays=NULL) { 

but it is very unpleasant, and I do not think that I need to change the definition of a function in order to document it. Does anyone have any other suggestions?

PS I am using PHPDocumentor2

+4
source share
1 answer

Your current syntax

 * @param DateTime $holidays,... Optional series of dates that will be excluded 

It looks correct according to the phpDocumentor manual for the param tag [1]. This page shows that the syntax "$ holidays, ..." must be sufficient for phpDocumentor to recognize an optional parameter that is not directly displayed in the code method signature.

This "Parameter $ of holidays, ... cannot be found in daysBetween ()", the answer probably needs a new problem that opens on the github [2] page.

[1] - http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.param.pkg.html

[2] - https://github.com/phpDocumentor/phpDocumentor2/issues/424

+4
source

Source: https://habr.com/ru/post/1402992/


All Articles