Skip to content

Commit

Permalink
Fix parameter name for WP_REST_Request::has_param() in functionMap (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Jul 14, 2024
1 parent 8f47cd1 commit 8b6e534
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
6 changes: 3 additions & 3 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
'rest_ensure_response' => ['($response is WP_Error ? WP_Error : WP_REST_Response)'],
'WP_REST_Request' => [null, '@phpstan-template' => 'T of array', '@phpstan-implements' => 'ArrayAccess<key-of<T>, value-of<T>>'],
'WP_REST_Request::offsetExists' => [null, 'offset' => 'key-of<T>'],
'WP_REST_Request::offsetGet' => ['T[TOffset]', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset'],
'WP_REST_Request::offsetGet' => ['($offset is TOffset ? T[TOffset] : null)', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset'],
'WP_REST_Request::offsetSet' => ['void', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset', 'value' => 'T[TOffset]'],
'WP_REST_Request::offsetUnset' => ['void', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset'],
'WP_REST_Request::get_param' => ['T[TOffset]', '@phpstan-template' => 'TOffset of key-of<T>', 'key' => 'TOffset'],
'WP_REST_Request::get_param' => ['($key is TOffset ? T[TOffset] : null)', '@phpstan-template' => 'TOffset of key-of<T>', 'key' => 'TOffset'],
'WP_REST_Request::get_params' => ['T'],
'WP_REST_Request::set_param' => ['void', '@phpstan-template' => 'TOffset of key-of<T>', 'key' => 'TOffset', 'value' => 'T[TOffset]'],
'WP_REST_Request::has_param' => [null, 'offset' => 'key-of<T>'],
'WP_REST_Request::has_param' => [null, 'key' => 'key-of<T>'],
'WP_Theme' => [null, '@phpstan-type' => "ThemeKey 'Name'|'Version'|'Status'|'Title'|'Author'|'Author Name'|'Author URI'|'Description'|'Template'|'Stylesheet'|'Template Files'|'Stylesheet Files'|'Template Dir'|'Stylesheet Dir'|'Screenshot'|'Tags'|'Theme Root'|'Theme Root URI'|'Parent Theme'"],
'WP_Theme::get' => ["(\$header is 'Name'|'ThemeURI'|'Description'|'Author'|'AuthorURI'|'Version'|'Template'|'Status'|'Tags'|'TextDomain'|'DomainPath'|'RequiresWP'|'RequiresPHP'|'UpdateURI' ? (\$header is 'Tags' ? string[] : string) : false)"],
'WP_Theme::offsetExists' => ['($offset is ThemeKey ? true : false)'],
Expand Down
19 changes: 16 additions & 3 deletions tests/data/wp_rest_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

use function PHPStan\Testing\assertType;

/**
* @var \WP_REST_Request<array> $request
*/
$request = new WP_REST_Request();

assertType('mixed', $request->get_param('maybeParam'));

assertType('mixed', $request['maybeParam']);

assertType('array', $request->get_params());

assertType('bool', $request->has_param('maybeParam'));

/**
* @var \WP_REST_Request<array{
* stringParam: string,
Expand All @@ -18,16 +31,16 @@
assertType('string', $request->get_param('stringParam'));
assertType('int', $request->get_param('intParam'));
assertType('bool', $request->get_param('boolParam'));
assertType('null', $request->get_param('unknownParam'));
assertType('null', $request->get_param('nonExistentParam'));

assertType('string', $request['stringParam']);
assertType('int', $request['intParam']);
assertType('bool', $request['boolParam']);
assertType('null', $request['unknownParam']);
assertType('null', $request['nonExistentParam']);

assertType('array{stringParam: string, intParam: int, boolParam: bool}', $request->get_params());

assertType('bool', $request->has_param('stringParam'));
assertType('bool', $request->has_param('intParam'));
assertType('bool', $request->has_param('boolParam'));
assertType('bool', $request->has_param('unknownParam'));
assertType('bool', $request->has_param('nonExistentParam'));
6 changes: 3 additions & 3 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -68946,7 +68946,7 @@ protected function get_parameter_order()
* @return mixed|null Value if set, null otherwise.
* @phpstan-template TOffset of key-of<T>
* @phpstan-param TOffset $key
* @phpstan-return T[TOffset]
* @phpstan-return ($key is TOffset ? T[TOffset] : null)
*/
public function get_param($key)
{
Expand All @@ -68961,7 +68961,7 @@ public function get_param($key)
*
* @param string $key Parameter name.
* @return bool True if a param exists for the given key.
* @phpstan-param key-of<T> $offset
* @phpstan-param key-of<T> $key
*/
public function has_param($key)
{
Expand Down Expand Up @@ -69261,7 +69261,7 @@ public function offsetExists($offset)
* @return mixed|null Value if set, null otherwise.
* @phpstan-template TOffset of key-of<T>
* @phpstan-param TOffset $offset
* @phpstan-return T[TOffset]
* @phpstan-return ($offset is TOffset ? T[TOffset] : null)
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
Expand Down

0 comments on commit 8b6e534

Please sign in to comment.