Skip to content

Signature of Method Forms/Container::extensionMethod should respect variable numbers of Arguments #355

Description

@micha-walter

Version: 3.3.0

Bug Description

PHP Stan reports this error, for Method Forms/Container::extensionMethod

Parameter #2 $callback of static method Nette\Forms\Container::extensionMethod() expects callable(Nette\Forms\Container): mixed, Closure(Nette\Forms\Container, string, string|Stringable|null=, string=): XYZInput given. 
💡 Parameter #2 $name of passed callable is required but accepting callable does not have that parameter. It will be called without it.PHPStan[argument.type](https://phpstan.org/error-identifiers/argument.type)

Steps To Reproduce

Create a Nette DI extension e.g.:

class XYZExtension extends CompilerExtension
{
  public function afterCompile(ClassType $class): void
  {
    $class->getMethod('initialize')
      ->addBody('\XYZExtension::register();');
  }

  /**
   * Register addXYZ() on every form Container.
   */
  public static function register(): void
  {
    Container::extensionMethod(
      'addXYZ,
      function (
        Container $container,
        string $name,
        string|Stringable|null $label = null,
        string $anotherParam = '',
      ): XYZInput {
        $control = new XYZInput($label, $anotherParam);
        $container->addComponent($control, $name);
        return $control;
      }
    );
  }
}

Expected Behavior

Signature of Method Forms\Container::extensionMethod should respect variable numbers of Arguments

Possible Solution

Possible Signature for Method Forms/Container::extensionMethod can be.

/** @param callable(static, ...mixed): mixed  $callback */
public static function extensionMethod(string $name, callable $callback): void

PHP runtime version: 8.3.25
PHPStan version: 2.2.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions