Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple variants #135

Merged
merged 2 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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