Skip to content

Commit 5a6fdcc

Browse files
authored
Narrow return type for did_filter() (#399)
1 parent b5803f9 commit 5a6fdcc

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
'current_filter' => ['non-empty-string|false'],
6767
'current_time' => ["(\$type is 'timestamp'|'U' ? int : string)"],
6868
'did_action' => ['int<0, max>'],
69+
'did_filter' => ['int<0, max>'],
6970
'edit_link' => ['int<0, max>'],
7071
'edit_term_link' => ['($display is true ? void : string|void)'],
7172
'get_approved_comments' => ["(\$args is array{count: true}&array ? int : (\$args is array{fields: 'ids'}&array ? array<int, int> : array<int, \WP_Comment>))"],

tests/data/return/did-action.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function did_action;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('int<0, max>', did_action('hook_name'));

tests/data/return/did-filter.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function did_filter;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('int<0, max>', did_filter('hook_name'));

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129546,6 +129546,7 @@ function doing_filter($hook_name = \null)
129546129546
*
129547129547
* @param string $hook_name The name of the filter hook.
129548129548
* @return int The number of times the filter hook has been applied.
129549+
* @phpstan-return int<0, max>
129549129550
*/
129550129551
function did_filter($hook_name)
129551129552
{

0 commit comments

Comments
 (0)