nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Missing possibility to add variadic parameter to a method #76

Closed Eydamos closed 3 years ago

Eydamos commented 3 years ago

Simple example:

$method = $class->addMethod('count')
                ->addParameter('entities')
                ->setType('object ...');

Would result in the following:

function count(object ... $entities)
{
}

The space between the variadic operator ... and the variable name $entities is not allowed by PSR12 standard. A method like setVariadic(bool $state = true): self; on the Nette\PhpGenerator\Parameter could help with that.

dg commented 3 years ago

Use setVariadic() on method.

Eydamos commented 3 years ago

Ok thank you. Would not have expected that on the method as the parameter is a variadic and not the method. But good that it is possible. Would be cool if you could add this to the documentation on https://doc.nette.org/

dg commented 3 years ago

If you can sent PR to documentation, it would be best.

https://github.com/nette/docs/blob/doc-3.1/en/php-generator.texy