Skip to content

Commit 3c9a59c

Browse files
committed
Generate stubs for WordPress 6.2.0
1 parent ebf6d8d commit 3c9a59c

File tree

7 files changed

+5752
-3446
lines changed

7 files changed

+5752
-3446
lines changed

finder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@
4141
//->notPath('wp-includes/theme-compat/footer.php')
4242
//->notPath('wp-includes/theme-compat/header.php')
4343
//->notPath('wp-includes/theme-compat/sidebar.php')
44+
// ->notPath('wp-includes/Requests/src')
4445
->sortByName()
4546
;

functionMap62.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
$httpReturnType = 'array{headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary, body: string, response: array{code: int,message: string}, cookies: array<int, \WP_HTTP_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
4+
$cronArgsType = 'list<mixed>';
5+
6+
/**
7+
* This array is in the same format as the function map array in PHPStan:
8+
*
9+
* '<function_name>' => ['<return_type>', '<arg_name>'=>'<arg_type>']
10+
*
11+
* @link https://github.com/phpstan/phpstan-src/blob/1.5.x/resources/functionMap.php
12+
*/
13+
return [
14+
'add_meta_box' => ['void', 'context'=>'"normal"|"side"|"advanced"', 'priority'=>'"high"|"core"|"default"|"low"'],
15+
'addslashes_gpc' => ['T', '@phpstan-template'=>'T', 'gpc'=>'T'],
16+
'have_posts' => ['bool', '@phpstan-impure'=>''],
17+
'rawurlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
18+
'remove_meta_box' => ['void', 'context'=>'"normal"|"side"|"advanced"'],
19+
'sanitize_category' => ['T', '@phpstan-template'=>'T of array|object', 'category'=>'T'],
20+
'sanitize_post' => ['T', '@phpstan-template'=>'T of array|object', 'post'=>'T'],
21+
'sanitize_term' => ['T', '@phpstan-template'=>'T of array|object', 'term'=>'T'],
22+
'stripslashes_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
23+
'urldecode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
24+
'urlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
25+
'wp_clear_scheduled_hook' => ['int|false|WP_Error', 'args'=>$cronArgsType],
26+
'wp_get_schedule' => ['string|false', 'args'=>$cronArgsType],
27+
'wp_get_scheduled_event' => ['object|false', 'args'=>$cronArgsType],
28+
'WP_Http::get' => [$httpReturnType],
29+
'WP_Http::head' => [$httpReturnType],
30+
'WP_Http::post' => [$httpReturnType],
31+
'WP_Http::request' => [$httpReturnType],
32+
'WP_List_Table::bulk_actions' => ['void', 'which'=>'"top"|"bottom"'],
33+
'WP_List_Table::display_tablenav' => ['void', 'which'=>'"top"|"bottom"'],
34+
'WP_List_Table::pagination' => ['void', 'which'=>'"top"|"bottom"'],
35+
'wp_next_scheduled' => ['int|false', 'args'=>$cronArgsType],
36+
'WP_Query::have_posts' => ['bool', '@phpstan-impure'=>''],
37+
'wp_remote_get' => [$httpReturnType],
38+
'wp_remote_head' => [$httpReturnType],
39+
'wp_remote_post' => [$httpReturnType],
40+
'wp_remote_request' => [$httpReturnType],
41+
'wp_reschedule_event' => ['bool|WP_Error', 'args'=>$cronArgsType],
42+
'wp_safe_remote_get' => [$httpReturnType],
43+
'wp_safe_remote_head' => [$httpReturnType],
44+
'wp_safe_remote_post' => [$httpReturnType],
45+
'wp_safe_remote_request' => [$httpReturnType],
46+
'wp_schedule_event' => ['bool|WP_Error', 'args'=>$cronArgsType],
47+
'wp_schedule_single_event' => ['bool|WP_Error', 'args'=>$cronArgsType],
48+
'wp_slash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
49+
'wp_unschedule_event' => ['bool|WP_Error', 'args'=>$cronArgsType],
50+
'wp_unslash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
51+
];

generate.sh

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,34 @@ if [ ! -d vendor ]; then
1414
composer update
1515
fi
1616

17-
# Exclude globals.
18-
"$(dirname "$0")/vendor/bin/generate-stubs" \
19-
--force \
20-
--finder=finder.php \
21-
--visitor=visitor.php \
22-
--header="$HEADER" \
23-
--functions \
24-
--classes \
25-
--interfaces \
26-
--traits \
27-
--out="$FILE"
17+
if [ -r source/wordpress/wp-includes/Requests/Cookie/Jar.php ]; then
18+
# Exclude globals.
19+
"$(dirname "$0")/vendor/bin/generate-stubs" \
20+
--force \
21+
--finder=finder.php \
22+
--visitor=visitor.php \
23+
--header="$HEADER" \
24+
--functions \
25+
--classes \
26+
--interfaces \
27+
--traits \
28+
--out="$FILE"
29+
else
30+
# Exclude globals.
31+
"$(dirname "$0")/vendor/bin/generate-stubs" \
32+
--force \
33+
--finder=finder.php \
34+
--visitor=visitor62.php \
35+
--header="$HEADER" \
36+
--functions \
37+
--classes \
38+
--interfaces \
39+
--traits \
40+
--out="$FILE"
41+
fi
2842

29-
## Use literal-string type for wpdb::prepare() query statement parameter.
30-
#sed -i -e 's#^.*@param string \+\$query \+Query statement.*$#&\n * @phpstan-param literal-string $query#' "$FILE"
43+
# Use literal-string type for wpdb::prepare() query statement parameter.
44+
sed -i -e 's#^.*@param string \+\$query \+Query statement.*$#&\n * @phpstan-param literal-string $query#' "$FILE"
3145

3246
# Shim the global $wpdb declaration, since it's actually set up inside a function call.
3347
if grep -qFx 'namespace {' "$FILE"; then
@@ -36,37 +50,39 @@ else
3650
printf '\n/**\n * WordPress database abstraction object.\n * @var wpdb\n */\n$wpdb = \\null;\n' >>"$FILE"
3751
fi
3852

39-
# Add ReturnTypeWillChange attribute to PHP 8-incompatible methods.
40-
declare -r -a REQUESTS_V1_METHODS=(
41-
"Requests_Cookie_Jar::getIterator"
42-
"Requests_Cookie_Jar::offsetExists"
43-
"Requests_Cookie_Jar::offsetGet"
44-
"Requests_Cookie_Jar::offsetSet"
45-
"Requests_Cookie_Jar::offsetUnset"
46-
"Requests_Utility_CaseInsensitiveDictionary::getIterator"
47-
"Requests_Utility_CaseInsensitiveDictionary::offsetExists"
48-
"Requests_Utility_CaseInsensitiveDictionary::offsetGet"
49-
"Requests_Utility_CaseInsensitiveDictionary::offsetSet"
50-
"Requests_Utility_CaseInsensitiveDictionary::offsetUnset"
51-
"Requests_Utility_FilteredIterator::current"
52-
"Requests_Utility_FilteredIterator::__unserialize"
53-
"Requests_Utility_FilteredIterator::unserialize"
54-
)
55-
for METHOD in "${REQUESTS_V1_METHODS[@]}"; do
56-
# Get the line number where the method is defined.
57-
LINE="$(php -r "require 'wordpress-stubs.php'; print (new ReflectionMethod('${METHOD}'))->getStartLine();")"
58-
if [ -z "${LINE}" ]; then
59-
continue
60-
fi
61-
echo "${METHOD} is defined on line ${LINE}."
53+
if [ -r source/wordpress/wp-includes/Requests/Cookie/Jar.php ]; then
54+
# Add ReturnTypeWillChange attribute to PHP 8-incompatible methods.
55+
declare -r -a REQUESTS_V1_METHODS=(
56+
"Requests_Cookie_Jar::getIterator"
57+
"Requests_Cookie_Jar::offsetExists"
58+
"Requests_Cookie_Jar::offsetGet"
59+
"Requests_Cookie_Jar::offsetSet"
60+
"Requests_Cookie_Jar::offsetUnset"
61+
"Requests_Utility_CaseInsensitiveDictionary::getIterator"
62+
"Requests_Utility_CaseInsensitiveDictionary::offsetExists"
63+
"Requests_Utility_CaseInsensitiveDictionary::offsetGet"
64+
"Requests_Utility_CaseInsensitiveDictionary::offsetSet"
65+
"Requests_Utility_CaseInsensitiveDictionary::offsetUnset"
66+
"Requests_Utility_FilteredIterator::current"
67+
"Requests_Utility_FilteredIterator::__unserialize"
68+
"Requests_Utility_FilteredIterator::unserialize"
69+
)
70+
for METHOD in "${REQUESTS_V1_METHODS[@]}"; do
71+
# Get the line number where the method is defined.
72+
LINE="$(php -r "require 'wordpress-stubs.php'; print (new ReflectionMethod('${METHOD}'))->getStartLine();")"
73+
if [ -z "${LINE}" ]; then
74+
continue
75+
fi
76+
echo "${METHOD} is defined on line ${LINE}."
6277

63-
# Check the previous line for ReturnTypeWillChange attribute.
64-
if sed -e "$((LINE - 1)) !d" "${FILE}" | grep -q -F '#[ReturnTypeWillChange]'; then
65-
continue
66-
fi
78+
# Check the previous line for ReturnTypeWillChange attribute.
79+
if sed -e "$((LINE - 1)) !d" "${FILE}" | grep -q -F '#[ReturnTypeWillChange]'; then
80+
continue
81+
fi
6782

68-
# Grab leading whitespace on the current line so we can indent ReturnTypeWillChange correctly.
69-
LEADING_WHITESPACES="$(sed -e "${LINE} !d;s#^\\(\\s\\+\\).*\$#\\1#" "${FILE}")"
70-
# Insert the ReturnTypeWillChange attribute.
71-
sed -i -e "${LINE} i\\" -e "${LEADING_WHITESPACES}#[ReturnTypeWillChange]" "${FILE}"
72-
done
83+
# Grab leading whitespace on the current line so we can indent ReturnTypeWillChange correctly.
84+
LEADING_WHITESPACES="$(sed -e "${LINE} !d;s#^\\(\\s\\+\\).*\$#\\1#" "${FILE}")"
85+
# Insert the ReturnTypeWillChange attribute.
86+
sed -i -e "${LINE} i\\" -e "${LEADING_WHITESPACES}#[ReturnTypeWillChange]" "${FILE}"
87+
done
88+
fi

release-latest-versions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CORE_JSON="$(wget -q -O- "https://packagist.org/packages/johnpbloch/wordpress-co
3737
#for MINOR in 4.7 4.8 4.9 \
3838
for MINOR in \
3939
5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 \
40-
6.0 6.1 6.2; do
40+
6.0 6.1 6.2 6.3 6.4; do
4141
# Find latest version
4242
printf -v JQ_FILTER '.package.versions[].version | select(test("^%s\\\\.%s\\\\.\\\\d+$"))' "${MINOR%.*}" "${MINOR#*.}"
4343
LATEST_FIVE="$(jq -r "$JQ_FILTER" <<<"$CORE_JSON" | sort -t "." -k 3 -g | tail -n 5)"

source/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ext-mbstring": "*",
88
"ext-openssl": "*",
99
"ext-sodium": "*",
10-
"johnpbloch/wordpress": "6.1.1"
10+
"johnpbloch/wordpress": "6.2.0"
1111
},
1212
"minimum-stability": "stable",
1313
"config": {

0 commit comments

Comments
 (0)