Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Jul 23, 2024
2 parents 4a0a920 + 86e8753 commit a49b3f1
Show file tree
Hide file tree
Showing 14 changed files with 3,164 additions and 697 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout repository"
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
],
"homepage": "https://github.com/php-stubs/wordpress-stubs",
"require-dev": {
"php": "^7.4 || ~8.0.0",
"php": "^7.4 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"nikic/php-parser": "^4.13",
"php-stubs/generator": "^0.8.3",
"phpdocumentor/reflection-docblock": "^5.4.1",
"phpstan/phpstan": "^1.10.49",
"phpunit/phpunit": "^9.5",
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11"
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0",
"wp-coding-standards/wpcs": "3.1.0 as 2.3.0"
},
"suggest": {
"paragonie/sodium_compat": "Pure PHP implementation of libsodium",
Expand Down
7 changes: 7 additions & 0 deletions finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@
//->notPath('wp-includes/theme-compat/footer.php')
//->notPath('wp-includes/theme-compat/header.php')
//->notPath('wp-includes/theme-compat/sidebar.php')
/*
->notPath('wp-includes/SimplePie')
->notPath('wp-includes/class-simplepie.php')
->notPath('wp-includes/class-wp-feed-cache.php')
->notPath('wp-includes/class-wp-simplepie-file.php')
->notPath('wp-includes/class-wp-simplepie-sanitize-kses.php')
*/
->sortByName();
14 changes: 11 additions & 3 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
*
* '<class_name>' => [null, '<arg_name>' => '<arg_type>']
*
* For class methods:
*
* '<class_name::method_name>' => ['<return_type>', '<arg_name>' => '<arg_type>']
*
* For class properties:
*
* '<class_name::$property_name>' => [null, '@phpstan-var' => '<property_type>']
*
* @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php
*/
return [
Expand Down Expand Up @@ -62,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' => ['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' => ['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
6 changes: 3 additions & 3 deletions release-latest-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Do_release()
CORE_JSON="$(wget -q -O- "https://packagist.org/packages/johnpbloch/wordpress-core.json")"

# @TODO Use branches!
#for MINOR in 4.7 4.8 4.9 \
#for MINOR in 4.7 4.8 4.9 \
# 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 \
for MINOR in \
5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 \
6.0 6.1 6.2 6.3 6.4 6.5 6.6; do
6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7; do
# Find latest version
printf -v JQ_FILTER '.package.versions[].version | select(test("^%s\\\\.%s\\\\.\\\\d+$"))' "${MINOR%.*}" "${MINOR#*.}"
LATEST_FIVE="$(jq -r "$JQ_FILTER" <<<"$CORE_JSON" | sort -t "." -k 3 -g | tail -n 5)"
Expand Down
2 changes: 1 addition & 1 deletion source/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-sodium": "*",
"johnpbloch/wordpress": "6.5.3"
"johnpbloch/wordpress": "6.6.0"
},
"minimum-stability": "stable",
"config": {
Expand Down
12 changes: 5 additions & 7 deletions src/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public function enterNode(Node $node)

$symbolName = self::getNodeName($node);

if ($node instanceof ClassMethod) {
if ($node instanceof ClassMethod || $node instanceof Property) {
$parent = $this->stack[count($this->stack) - 2];
\assert($parent instanceof \PhpParser\Node\Stmt\ClassLike);

if ($parent->name !== null) {
$symbolName = sprintf(
'%1$s::%2$s',
'%1$s::%2$s%3$s',
$parent->name->name,
$node->name->name
$node instanceof Property ? '$' : '',
$symbolName
);
}
}
Expand Down Expand Up @@ -125,10 +126,7 @@ private static function getNodeName(Node $node): string
}

if ($node instanceof Property) {
return sprintf(
'property_%s',
uniqid()
);
return $node->props[0]->name->name;
}

return '';
Expand Down
16 changes: 8 additions & 8 deletions tests/data/get_term.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

declare( strict_types=1 );
declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function get_term;
use function PHPStan\Testing\assertType;

assertType( 'WP_Error|WP_Term|null', get_term( 2, '', OBJECT ) );
assertType( 'WP_Error|WP_Term|null', get_term( 2, 'category', OBJECT ) );
assertType( 'WP_Error|WP_Term|null', get_term( 2 ) );
assertType('WP_Error|WP_Term|null', get_term(2, '', OBJECT));
assertType('WP_Error|WP_Term|null', get_term(2, 'category', OBJECT));
assertType('WP_Error|WP_Term|null', get_term(2));

assertType( 'array<string, int|string>|WP_Error|null', get_term( 2, '', ARRAY_A ) );
assertType( 'array<string, int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_A ) );
assertType( 'list<int|string>|WP_Error|null', get_term( 2, '', ARRAY_N ) );
assertType( 'list<int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_N ) );
assertType('array<string, int|string>|WP_Error|null', get_term(2, '', ARRAY_A));
assertType('array<string, int|string>|WP_Error|null', get_term(2, 'category', ARRAY_A));
assertType('list<int|string>|WP_Error|null', get_term(2, '', ARRAY_N));
assertType('list<int|string>|WP_Error|null', get_term(2, 'category', ARRAY_N));
10 changes: 5 additions & 5 deletions tests/data/get_term_by.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare( strict_types=1 );
declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function get_term_by;
use function PHPStan\Testing\assertType;

assertType( 'WP_Error|WP_Term|false', get_term_by( 'term_id', 2, '', OBJECT ) );
assertType( 'WP_Error|WP_Term|false', get_term_by( 'slug', 'test' ) );
assertType( 'array<string, int|string>|WP_Error|false', get_term_by( 'term_id', 2, '', ARRAY_A ) );
assertType( 'list<int|string>|WP_Error|false', get_term_by( 'term_id', 2, '', ARRAY_N ) );
assertType('WP_Error|WP_Term|false', get_term_by('term_id', 2, '', OBJECT));
assertType('WP_Error|WP_Term|false', get_term_by('slug', 'test'));
assertType('array<string, int|string>|WP_Error|false', get_term_by('term_id', 2, '', ARRAY_A));
assertType('list<int|string>|WP_Error|false', get_term_by('term_id', 2, '', ARRAY_N));
1 change: 0 additions & 1 deletion tests/data/rest_ensure_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use WP_Error;
use WP_REST_Response;
use function get_term;
use function PHPStan\Testing\assertType;

assertType('WP_Error', rest_ensure_response(new WP_Error()));
Expand Down
4 changes: 2 additions & 2 deletions tests/data/wp_debug_backtrace_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
use function PHPStan\Testing\assertType;

assertType('string', wp_debug_backtrace_summary());
assertType('string', wp_debug_backtrace_summary( null, 0, true ));
assertType('list<string>', wp_debug_backtrace_summary( null, 0, false ));
assertType('string', wp_debug_backtrace_summary(null, 0, true));
assertType('list<string>', wp_debug_backtrace_summary(null, 0, false));
24 changes: 12 additions & 12 deletions tests/data/wp_error_parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@
use function wp_update_post;
use function PHPStan\Testing\assertType;

/**
/*
* wp_insert_link()
*/
assertType('int<0, max>', wp_insert_link([]));
assertType('int<0, max>', wp_insert_link([], false));
assertType('int<1, max>|WP_Error', wp_insert_link([], true));
assertType('int<0, max>|WP_Error', wp_insert_link([], $_GET['wp_error']));

/**
/*
* wp_insert_category()
*/
assertType('int<0, max>', wp_insert_category([]));
assertType('int<0, max>', wp_insert_category([], false));
assertType('int<1, max>|WP_Error', wp_insert_category([], true));
assertType('int<0, max>|WP_Error', wp_insert_category([], $_GET['wp_error']));

/**
/*
* wp_set_comment_status()
*/
assertType('bool', wp_set_comment_status(1, 'spam'));
assertType('bool', wp_set_comment_status(1, 'spam', false));
assertType('WP_Error|true', wp_set_comment_status(1, 'spam', true));
assertType('bool|WP_Error', wp_set_comment_status(1, 'spam', $_GET['wp_error']));

/**
/*
* wp_update_comment()
*/
assertType('0|1|false', wp_update_comment([]));
assertType('0|1|false', wp_update_comment([], false));
assertType('0|1|WP_Error', wp_update_comment([], true));
assertType('0|1|WP_Error|false', wp_update_comment([], $_GET['wp_error']));

/**
/*
* wp_schedule_single_event()
*/
assertType('bool', wp_schedule_single_event(1, 'hook'));
Expand All @@ -60,7 +60,7 @@
assertType('WP_Error|true', wp_schedule_single_event(1, 'hook', [], true));
assertType('bool|WP_Error', wp_schedule_single_event(1, 'hook', [], $_GET['wp_error']));

/**
/*
* wp_schedule_event()
*/
assertType('bool', wp_schedule_event(1, 'daily', 'hook'));
Expand All @@ -78,7 +78,7 @@
assertType('WP_Error|true', wp_reschedule_event(1, 'daily', 'hook', [], true));
assertType('bool|WP_Error', wp_reschedule_event(1, 'daily', 'hook', [], $_GET['wp_error']));

/**
/*
* wp_unschedule_event()
*/
assertType('bool', wp_unschedule_event(1, 'hook'));
Expand All @@ -87,7 +87,7 @@
assertType('WP_Error|true', wp_unschedule_event(1, 'hook', [], true));
assertType('bool|WP_Error', wp_unschedule_event(1, 'hook', [], $_GET['wp_error']));

/**
/*
* wp_clear_scheduled_hook()
*/
assertType('int<0, max>|false', wp_clear_scheduled_hook('hook'));
Expand All @@ -96,15 +96,15 @@
assertType('int<0, max>|WP_Error', wp_clear_scheduled_hook('hook', [], true));
assertType('int<0, max>|WP_Error|false', wp_clear_scheduled_hook('hook', [], $_GET['wp_error']));

/**
/*
* wp_unschedule_hook()
*/
assertType('int<0, max>|false', wp_unschedule_hook('hook'));
assertType('int<0, max>|false', wp_unschedule_hook('hook', false));
assertType('int<0, max>|WP_Error', wp_unschedule_hook('hook', true));
assertType('int<0, max>|WP_Error|false', wp_unschedule_hook('hook', $_GET['wp_error']));

/**
/*
* wp_insert_post()
*/
assertType('int<0, max>', wp_insert_post([]));
Expand All @@ -118,7 +118,7 @@
assertType('int<0, max>|WP_Error', wp_insert_post([], $_GET['wp_error'], true));
assertType('int<0, max>|WP_Error', wp_insert_post([], $_GET['wp_error'], false));

/**
/*
* wp_update_post()
*/
assertType('int<0, max>', wp_update_post([]));
Expand All @@ -132,7 +132,7 @@
assertType('int<0, max>|WP_Error', wp_update_post([], $_GET['wp_error'], true));
assertType('int<0, max>|WP_Error', wp_update_post([], $_GET['wp_error'], false));

/**
/*
* wp_insert_attachment()
*/
assertType('int<0, max>', wp_insert_attachment([]));
Expand Down
43 changes: 35 additions & 8 deletions tests/data/wp_rest_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@

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<string, string>> $request
*/
$request = new WP_REST_Request();

assertType('string|null', $request->get_param('maybeParam'));

assertType('string|null', $request['maybeParam']);

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

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

/**
* @var \WP_REST_Request<array{
* stringParam: string,
Expand All @@ -15,18 +41,19 @@
*/
$request = new WP_REST_Request();

assertType('string', $request->get_param('stringParam'));
assertType('int', $request->get_param('intParam'));
assertType('bool', $request->get_param('boolParam'));
assertType('string|null', $request->get_param('stringParam'));
assertType('int|null', $request->get_param('intParam'));
assertType('bool|null', $request->get_param('boolParam'));
assertType('bool|int|string|null', $request->get_param('nonExistentParam'));

assertType('string', $request['stringParam']);
assertType('int', $request['intParam']);
assertType('bool', $request['boolParam']);
assertType('bool|int|string', $request['unknownParam']);
assertType('string|null', $request['stringParam']);
assertType('int|null', $request['intParam']);
assertType('bool|null', $request['boolParam']);
assertType('bool|int|string|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'));
Loading

0 comments on commit a49b3f1

Please sign in to comment.