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 Aug 23, 2024
2 parents a49b3f1 + c0bd4b0 commit 40c7a36
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array<array-key, mixed> : (\$output is 'ARRAY_N' ? list<mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|positive-int'],
'wpdb::get_results' => ["null|(\$output is 'ARRAY_A' ? list<array<array-key, mixed>> : (\$output is 'ARRAY_N' ? list<array<int, mixed>> : (\$output is 'OBJECT_K' ? array<array-key, \stdClass> : list<\stdClass>)))", 'output' => "'OBJECT'|'OBJECT_K'|'ARRAY_A'|'ARRAY_N'"],
'get_bookmark' => ["null|(\$output is 'ARRAY_A' ? array<string, mixed> : (\$output is 'ARRAY_N' ? array<int, mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
'get_categories' => ["(\$args is array{fields: 'count'} ? list<numeric-string> : (\$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>)))))"],
'get_category' => ["(\$category is object ? array<array-key, mixed>|\WP_Term : array<array-key, mixed>|\WP_Term|\WP_Error|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|\WP_Error|null : (\$output is 'ARRAY_N' ? array<int, mixed>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
'get_category_by_path' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|\WP_Error|null : (\$output is 'ARRAY_N' ? array<int, mixed>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
'WP_Widget' => [null, '@phpstan-template' => 'T of array<string, mixed>'],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/echo_parameter.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_attachment_taxonomies.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_bookmark.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_categories.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category_by_path.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_comment.php');
Expand Down
37 changes: 37 additions & 0 deletions tests/data/get_categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function get_categories;
use function PHPStan\Testing\assertType;

// Default argument values (fields => all)
assertType('array<int, WP_Term>', get_categories());
assertType('array<int, WP_Term>', get_categories([]));

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

// Requesting names or slugs
assertType('list<string>', get_categories(['fields' => 'names']));
assertType('list<string>', get_categories(['fields' => 'slugs']));
assertType('array<int, string>', get_categories(['fields' => 'id=>name']));
assertType('array<int, string>', get_categories(['fields' => 'id=>slug']));

// Requesting IDs
assertType('list<int>', get_categories(['fields' => 'ids']));
assertType('list<int>', get_categories(['fields' => 'tt_ids']));

// Requesting parent IDs
assertType('array<int, int>', get_categories(['fields' => 'id=>parent']));

// 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, int|string|WP_Term>', get_categories(['fields' => (string)$_GET['fields']]));
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -102562,6 +102562,7 @@ function has_term($term = '', $taxonomy = '', $post = \null)
* @phpstan-param array{
* taxonomy?: string,
* } $args
* @phpstan-return ($args is array{fields: 'count'} ? list<numeric-string> : ($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>)))))
*/
function get_categories($args = '')
{
Expand Down

0 comments on commit 40c7a36

Please sign in to comment.