Skip to content

Commit

Permalink
Add cond. return type for wp_parse_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Aug 26, 2024
1 parent 49019d0 commit 86d768f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@
'WP_Widget::form' => [null, 'instance' => 'T'],
'WP_Widget::update' => [null, 'new_instance' => 'T', 'old_instance' => 'T'],
'WP_Widget::widget' => [null, 'instance' => 'T', 'args' => 'array{name:string,id:string,description:string,class:string,before_widget:string,after_widget:string,before_title:string,after_title:string,before_sidebar:string,after_sidebar:string,show_in_rest:boolean,widget_id:string,widget_name:string}'],
'wp_parse_list' => ['($input_list is array ? array<scalar> : list<string>)'],
'wp_parse_str' => [null, '@phpstan-param-out' => 'array<int|string, array|string> $result'],
];
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_parse_list.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php');
Expand Down
10 changes: 10 additions & 0 deletions tests/data/wp_parse_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function PHPStan\Testing\assertType;

assertType('list<string>', wp_parse_list((string)$_GET['input_list']));
assertType('array<bool|float|int|string>', wp_parse_list((array)$_GET['input_list']));
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -114324,6 +114324,7 @@ function wp_parse_args($args, $defaults = array())
*
* @param array|string $input_list List of values.
* @return array Array of values.
* @phpstan-return ($input_list is array ? array<scalar> : list<string>)
*/
function wp_parse_list($input_list)
{
Expand Down

0 comments on commit 86d768f

Please sign in to comment.