How to document parameters received by the "func_get_args" function?

Asked

Viewed 57 times

2

How can I be documenting parameters that are received through the function func_get_args?

The reason is that you can pass several parameters to the function with the same purpose!

/**
 * Gets a smart text filtered and formatted of according with the property name provided
 *
 * @param string $code The property name to be called
 *
 * @return string Returns the content of property in `$code` with formatting filter as a string
 * @see   Skreth\Code\Text::getTexts()
 * @since 0.2
 */
public static function code($code)
{
    if (!is_string($code)) throw new InvalidArgumentException("Smart text is not a string");

    return StringFilter::formatting(self::getTexts($code));
}

As such, it may be possible to pass several $code:

public static function code()
{
    $code = func_num_args();
    $result = [];

    foreach ($code as $value) {
        if (!is_string($value)) throw new InvalidArgumentException("Smart text is not a string");

        $result[] =  StringFilter::formatting(self::getTexts($value));
    }

    // OU, TALVEZ (Acredito que foreach seja mais perfomático, estou certo?)...
    $result = array_map(function ($value) {
        if (!is_string($value)) throw new InvalidArgumentException("Smart text is not a string");

        return StringFilter::formatting(self::getTexts($value));
    }, $code);

    return implode(' ', $result);
}

I accept good programming practice tips too :D

1 answer

2


According to the answer in Soen

The old way would be:

http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.param.pkg.html

/**
 * @param int $param,...
 **/

However this is no longer supported, since PHP5.6 the Variadic Method Parameters are part of PHP and Phpdoc has also updated to this. It seems to work on the Phpstorm IDE since the EAP 139.659 (8.0.2+). I’m not sure about other Ides.

https://youtrack.jetbrains.com/issue/WI-20157

In all cases the appropriate syntax is this:

/**
 * @param int ...$param
 **/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.