Skip to content

Commit 582cfbc

Browse files
authored
Narrow return type of wp_get_server_protocol (#296)
1 parent 0daa228 commit 582cfbc

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
'wp_get_post_terms' => ["(\$post_id is 0 ? array{} : (\$taxonomy is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array<int, string> : (\$args is array{fields: 'id=>parent'}&array ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list<int> : (\$args is array{fields: 'count'}&array ? numeric-string : array<int, \WP_Term>)))))|\WP_Error)))"],
134134
'wp_get_schedule' => [null, 'args' => $cronArgsType],
135135
'wp_get_scheduled_event' => [null, 'args' => $cronArgsType],
136+
'wp_get_server_protocol' => ["'HTTP/1.0'|'HTTP/1.1'|'HTTP/2'|'HTTP/2.0'|'HTTP/3'"],
136137
'wp_insert_attachment' => ['($wp_error is false ? int<0, max> : int<1, max>|\WP_Error)'],
137138
'wp_insert_category' => ['($wp_error is false ? int<0, max> : int<1, max>|\WP_Error)'],
138139
'wp_insert_link' => ['($wp_error is false ? int<0, max> : int<1, max>|\WP_Error)'],

tests/TypeInferenceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function dataFileAsserts(): iterable
6464
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_post_tags.php');
6565
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_post_terms.php');
6666
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_object_terms.php');
67+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_server_protocol.php');
6768
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_is_numeric_array.php');
6869
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php');
6970
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function wp_get_server_protocol;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType("'HTTP/1.0'|'HTTP/1.1'|'HTTP/2'|'HTTP/2.0'|'HTTP/3'", wp_get_server_protocol());
11+
assertType('false', wp_get_server_protocol() === 'HTTP/1');
12+
assertType('bool', wp_get_server_protocol() === 'HTTP/3');
13+
assertType('bool', wp_get_server_protocol() === Faker::string());

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121207,6 +121207,7 @@ function wp_is_internal_link($link)
121207121207
* @since 4.4.0
121208121208
*
121209121209
* @return string The HTTP protocol. Default: HTTP/1.0.
121210+
* @phpstan-return 'HTTP/1.0'|'HTTP/1.1'|'HTTP/2'|'HTTP/2.0'|'HTTP/3'
121210121211
*/
121211121212
function wp_get_server_protocol()
121212121213
{

0 commit comments

Comments
 (0)