Skip to content

Commit

Permalink
Support multiple variants (#135)
Browse files Browse the repository at this point in the history
* Add a failing test for #133.

* Avoid a PHPStan exception when a callback has multiple variants.
  • Loading branch information
johnbillion committed Dec 1, 2022
1 parent 3934e62 commit 2778454
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/HookCallbackRule.php
Expand Up @@ -80,7 +80,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$callbackAcceptor = ParametersAcceptorSelector::selectSingle($callbackType->getCallableParametersAcceptors($scope));
$parametersAcceptors = $callbackType->getCallableParametersAcceptors($scope);
$callbackAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $args, $parametersAcceptors);

try {
if ($name->toString() === 'add_action') {
Expand Down
18 changes: 18 additions & 0 deletions tests/data/hook-callback.php
Expand Up @@ -234,6 +234,24 @@
add_filter('filter', __NAMESPACE__ . '\\filter_variadic_typed', 10, 2);
add_filter('filter', __NAMESPACE__ . '\\filter_variadic_typed', 10, 999);

// Multiple callbacks with varying signatures
class MultipleSignatures {
const ACTIONS = array(
'one',
'two',
);

public static function init(): void {
foreach ( self::ACTIONS as $action ) {
add_action( 'action', array( self::class, $action ) );
}
}

public static function one( int $param ): void {}

public static function two( string $param ): void {}
}

/**
* Symbol definitions for use in these tests.
*/
Expand Down

0 comments on commit 2778454

Please sign in to comment.