Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into import-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Aug 26, 2024
2 parents 4597207 + 49019d0 commit bb355e3
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 37 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@
'wp_get_post_terms' => ["(\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : array<int, \WP_Term>))))|\WP_Error"],
'wp_get_object_terms' => ["(\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : array<int, \WP_Term>))))|\WP_Error"],
'wp_parse_str' => [null, '@param-out' => 'array<int|string, array|string> $result'],

Check failure on line 169 in functionMap.php

View workflow job for this annotation

GitHub Actions / test (8.0)

Array has 2 duplicate keys with value 'wp_parse_str' ('wp_parse_str', 'wp_parse_str').

Check failure on line 169 in functionMap.php

View workflow job for this annotation

GitHub Actions / test (8.2)

Array has 2 duplicate keys with value 'wp_parse_str' ('wp_parse_str', 'wp_parse_str').

Check failure on line 169 in functionMap.php

View workflow job for this annotation

GitHub Actions / test (8.3)

Array has 2 duplicate keys with value 'wp_parse_str' ('wp_parse_str', 'wp_parse_str').
'wp_parse_str' => [null, '@phpstan-param-out' => 'array<int|string, array|string> $result'],
];
36 changes: 36 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,47 @@
<file>functionMap.php</file>
<file>src/</file>
<file>visitor.php</file>
<file>tests/</file>

<rule ref="PSR12NeutronRuleset">
<exclude name="Generic.Files.LineLength"/>
<exclude name="PEAR.Commenting.ClassComment"/>
<exclude name="PEAR.Commenting.FileComment"/>
</rule>

<!-- Rules not applied to tests -->
<rule ref="PSR12NeutronRuleset.NamingConventions.MeaningfulVariableName">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="PSR12NeutronRuleset.Strings.ConcatenationUsage">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions">
<properties>
<property name="ignoredNames" type="array">
<element value="WP_Error"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="Squiz.PHP.CommentedOutCode">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="WordPress.DateTime.CurrentTimeTimestamp">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="WordPress.DB.PreparedSQL">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="WordPress.Security.NonceVerification">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="NeutronStandard.Functions.TypeHint.UnusedReturnType">
<exclude-pattern>tests/TypeInferenceTest.php</exclude-pattern>
</rule>
</ruleset>
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace PhpStubs\WordPress\Core\Tests;

// phpcs:disable Squiz.PHP.DiscouragedFunctions
define('OBJECT', 'OBJECT');
define('ARRAY_A', 'ARRAY_A');
define('ARRAY_N', 'ARRAY_N');
// phpcs:enable
16 changes: 8 additions & 8 deletions tests/data/get_attachment_taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
use function PHPStan\Testing\assertType;

// Default
assertType('array<int, string>', get_attachment_taxonomies((int)$id));
assertType('array<int, string>', get_attachment_taxonomies((int)$id, 'names'));
assertType('array<int, string>', get_attachment_taxonomies((int)$_GET['id']));
assertType('array<int, string>', get_attachment_taxonomies((int)$_GET['id'], 'names'));

// Objects
assertType('array<string, WP_Taxonomy>', get_attachment_taxonomies((int)$id, 'objects'));
assertType('array<string, WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], 'objects'));

// Unexpected
assertType('array<string, WP_Taxonomy>', get_attachment_taxonomies((int)$id, 'Hello'));
assertType('array<string, WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], 'Hello'));

// Unknown
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$id, (string)$_GET['string']));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], (string)$_GET['string']));

// Unions
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$id, $_GET['foo'] ? 'names' : 'objects'));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$id, $_GET['foo'] ? (string)$_GET['string'] : 'names'));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$id, $_GET['foo'] ? (string)$_GET['string'] : 'objects'));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], $_GET['foo'] ? 'names' : 'objects'));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], $_GET['foo'] ? (string)$_GET['string'] : 'names'));
assertType('array<int|string, string|WP_Taxonomy>', get_attachment_taxonomies((int)$_GET['id'], $_GET['foo'] ? (string)$_GET['string'] : 'objects'));
2 changes: 1 addition & 1 deletion tests/data/get_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use function PHPStan\Testing\assertType;

/** @var \stdClass|int $bookmark */
$bookmark;
$bookmark = $_GET['bookmark'];

assertType('stdClass|null', get_bookmark($bookmark));
assertType('stdClass|null', get_bookmark($bookmark, 'OBJECT'));
Expand Down
4 changes: 2 additions & 2 deletions tests/data/get_categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Requesting a count
assertType('list<numeric-string>', get_categories(['fields' => 'count']));
assertType('list<numeric-string>', get_categories(['foo' => 'bar','fields' => 'count']));
assertType('list<numeric-string>', get_categories(['fields' => 'count', 'foo' => 'bar']));

// Requesting names or slugs
assertType('list<string>', get_categories(['fields' => 'names']));
Expand All @@ -31,7 +31,7 @@
// Requesting objects
assertType('array<int, WP_Term>', get_categories(['fields' => 'all']));
assertType('array<int, WP_Term>', get_categories(['fields' => 'all_with_object_id']));
assertType('array<int, WP_Term>', get_categories(['fields' => 'foo']));

// Unknown fields value
assertType('array<int, WP_Term>', get_categories(['fields' => 'foo']));
assertType('array<int, int|string|WP_Term>', get_categories(['fields' => (string)$_GET['fields']]));
4 changes: 2 additions & 2 deletions tests/data/get_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
use function PHPStan\Testing\assertType;

/** @var object $category */
$category;
$category = $_GET['category'];

assertType('WP_Term', get_category($category));
assertType('WP_Term', get_category($category, 'OBJECT'));
assertType('array<string, mixed>', get_category($category, 'ARRAY_A'));
assertType('array<int, mixed>', get_category($category, 'ARRAY_N'));

/** @var int|object $category */
$category;
$category = $_GET['category'];

assertType('WP_Error|WP_Term|null', get_category($category));
assertType('WP_Error|WP_Term|null', get_category($category, 'OBJECT'));
Expand Down
11 changes: 4 additions & 7 deletions tests/data/get_category_by_path.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
use function get_category_by_path;
use function PHPStan\Testing\assertType;

/** @var bool $bool */
$bool;

assertType('WP_Error|WP_Term|null', get_category_by_path('', $bool));
assertType('WP_Error|WP_Term|null', get_category_by_path('', $bool, 'OBJECT'));
assertType('array<string, mixed>|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_A'));
assertType('array<int, mixed>|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_N'));
assertType('WP_Error|WP_Term|null', get_category_by_path('', (bool)$_GET['full_match']));
assertType('WP_Error|WP_Term|null', get_category_by_path('', (bool)$_GET['full_match'], 'OBJECT'));
assertType('array<string, mixed>|WP_Error|null', get_category_by_path('', (bool)$_GET['full_match'], 'ARRAY_A'));
assertType('array<int, mixed>|WP_Error|null', get_category_by_path('', (bool)$_GET['full_match'], 'ARRAY_N'));
4 changes: 2 additions & 2 deletions tests/data/get_comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use function PHPStan\Testing\assertType;

/** @var \WP_Comment|int|string|null $comment */
$comment;
$comment = $_GET['comment'];

// Default output
assertType('WP_Comment|null', get_comment());
Expand All @@ -22,7 +22,7 @@
assertType('array<int, mixed>|null', get_comment($comment, 'ARRAY_N'));

/** @var \WP_Comment $comment */
$comment;
$comment = $_GET['comment'];

assertType('WP_Comment', get_comment($comment));
assertType('WP_Comment', get_comment($comment, 'OBJECT'));
Expand Down
2 changes: 1 addition & 1 deletion tests/data/get_permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function PHPStan\Testing\assertType;

/** @var \WP_Post $post */
$post = $post;
$post = $_GET['post'];

// get_permalink()
assertType('string|false', get_permalink());
Expand Down
4 changes: 2 additions & 2 deletions tests/data/get_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use function PHPStan\Testing\assertType;

/** @var \WP_Post|int|null $post */
$post;
$post = $_GET['post'];

// Default output
assertType('WP_Post|null', get_post());
Expand All @@ -22,7 +22,7 @@
assertType('array<int, mixed>|null', get_post($post, 'ARRAY_N'));

/** @var \WP_Post $post */
$post;
$post = $_GET['post'];

assertType('WP_Post', get_post($post));
assertType('WP_Post', get_post($post, 'OBJECT'));
Expand Down
3 changes: 1 addition & 2 deletions tests/data/wp_die.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
assertType('null', wp_die('', '', (array)$_GET['args']));

// non-array $args parameter ($args not string type per @phpstan-param)
/** @var int $args */
assertType('never', wp_die('', '', $args));
assertType('never', wp_die('', '', (int)$_GET['args']));
4 changes: 2 additions & 2 deletions tests/data/wp_dropdown_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use function PHPStan\Testing\assertType;

/** @var ''|null $emptyStringOrNull */
$emptyStringOrNull = $_GET['nullOrEmptyString'];
$emptyStringOrNull = $_GET['emptyStringOrNull'];

/** @var string|null $stringOrNull */
$stringOrNull = $_GET['unknown'];
$stringOrNull = $_GET['stringOrNull'];

// Default value
assertType('string', wp_dropdown_languages());
Expand Down
4 changes: 2 additions & 2 deletions tests/data/wp_get_archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
assertType('string', wp_get_archives(['echo' => 0, 'key' => 'value']));

// Unknown value
assertType('string|null', wp_get_archives(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_get_archives(['echo' => (int)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_get_archives(['echo' => (bool)$_GET['echo'], 'key' => 'value']));
assertType('string|null', wp_get_archives(['echo' => (int)$_GET['echo'], 'key' => 'value']));
4 changes: 2 additions & 2 deletions tests/data/wp_list_bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
assertType('string', wp_list_bookmarks(['echo' => 0, 'key' => 'value']));

// Unknown value
assertType('string|null', wp_list_bookmarks(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_list_bookmarks(['echo' => (int)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_list_bookmarks(['echo' => (bool)$_GET['echo'], 'key' => 'value']));
assertType('string|null', wp_list_bookmarks(['echo' => (int)$_GET['echo'], 'key' => 'value']));
4 changes: 2 additions & 2 deletions tests/data/wp_list_categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
assertType('string|false', wp_list_categories(['echo' => 0, 'key' => 'value']));

// Unknown value
assertType('string|false|null', wp_list_categories(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|false|null', wp_list_categories(['echo' => (int)$GET['echo'], 'key' => 'value']));
assertType('string|false|null', wp_list_categories(['echo' => (bool)$_GET['echo'], 'key' => 'value']));
assertType('string|false|null', wp_list_categories(['echo' => (int)$_GET['echo'], 'key' => 'value']));
2 changes: 1 addition & 1 deletion tests/data/wp_list_pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
assertType('string', wp_list_pages(['echo' => false, 'key' => 'value']));

// Unknown value
assertType('string|null', wp_list_pages(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_list_pages(['echo' => (bool)$_GET['echo'], 'key' => 'value']));
2 changes: 1 addition & 1 deletion wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -112094,7 +112094,7 @@ function map_deep($value, $callback)
*
* @param string $input_string The string to be parsed.
* @param array $result Variables will be stored in this array.
* @param-out array<int|string, array|string> $result
* @phpstan-param-out array<int|string, array|string> $result
*/
function wp_parse_str($input_string, &$result)
{
Expand Down

0 comments on commit bb355e3

Please sign in to comment.