Skip to content

Commit 2778454

Browse files
authored
Support multiple variants (#135)
* Add a failing test for #133. * Avoid a PHPStan exception when a callback has multiple variants.
1 parent 3934e62 commit 2778454

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/HookCallbackRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function processNode(Node $node, Scope $scope): array
8080
return [];
8181
}
8282

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

8586
try {
8687
if ($name->toString() === 'add_action') {

tests/data/hook-callback.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,24 @@
234234
add_filter('filter', __NAMESPACE__ . '\\filter_variadic_typed', 10, 2);
235235
add_filter('filter', __NAMESPACE__ . '\\filter_variadic_typed', 10, 999);
236236

237+
// Multiple callbacks with varying signatures
238+
class MultipleSignatures {
239+
const ACTIONS = array(
240+
'one',
241+
'two',
242+
);
243+
244+
public static function init(): void {
245+
foreach ( self::ACTIONS as $action ) {
246+
add_action( 'action', array( self::class, $action ) );
247+
}
248+
}
249+
250+
public static function one( int $param ): void {}
251+
252+
public static function two( string $param ): void {}
253+
}
254+
237255
/**
238256
* Symbol definitions for use in these tests.
239257
*/

0 commit comments

Comments
 (0)