Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'get_comment' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Comment|null))"],
'get_post' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))"],
'get_page_by_path' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))"],
'get_term' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))"],
'has_action' => ['($callback is false ? bool : false|int)'],
'has_filter' => ['($callback is false ? bool : false|int)'],
'get_permalink' => ['($post is \WP_Post ? string : string|false)'],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_page_by_path.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_permalink.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies_for_attachments.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/has_filter.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php');
Expand Down
17 changes: 17 additions & 0 deletions tests/data/get_term.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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( '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( 'array<int, int|string>|WP_Error|null', get_term( 2, '', ARRAY_N ) );
assertType( 'array<int, int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_N ) );
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -129467,6 +129467,7 @@ function get_tax_sql($tax_query, $primary_table, $primary_id_column)
* @param string $filter Optional. How to sanitize term fields. Default 'raw'.
* @return WP_Term|array|WP_Error|null WP_Term instance (or array) on success, depending on the `$output` value.
* WP_Error if `$taxonomy` does not exist. Null for miscellaneous failure.
* @phpstan-return ($output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : ($output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))
*/
function get_term($term, $taxonomy = '', $output = \OBJECT, $filter = 'raw')
{
Expand Down