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 @@ -133,6 +133,7 @@
'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
'stripslashes_from_strings_only' => ["(\$value is string ? (\$value is '' ? '' : string) : T)", '@phpstan-template' => 'T', 'value' => 'T|string'],
'tag_exists' => ["(\$tag_name is 0 ? 0 : (\$tag_name is '' ? null : array{term_id: string, term_taxonomy_id: string}|null))"],
'taxonomy_exists' => ['($taxonomy is non-falsy-string ? bool : false)', '@phpstan-impure' => '', '@phpstan-assert-if-true' => '=non-falsy-string $taxonomy'],
'term_exists' => ["(\$term is 0 ? 0 : (\$term is '' ? null : (\$taxonomy is '' ? string|null : array{term_id: string, term_taxonomy_id: string}|null)))"],
'the_date' => ['($display is true ? void : string)'],
'the_modified_date' => ['($display is true ? void : string)'],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/sanitize_title_with_dashes.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/size_format.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/stripslashes.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/taxonomy_exists.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/term_exists.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/trailingslashit.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/validate_file.php');
Expand Down
50 changes: 50 additions & 0 deletions tests/data/taxonomy_exists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function taxonomy_exists;
use function PHPStan\Testing\assertType;

/*
* Check return type
*/

assertType('false', taxonomy_exists(''));
assertType('false', taxonomy_exists('0'));
assertType('bool', taxonomy_exists('tax'));
assertType('bool', taxonomy_exists(Faker::string()));
assertType('bool', taxonomy_exists(Faker::nonEmptyString()));
assertType('bool', taxonomy_exists(Faker::nonFalsyString()));

/*
* Check impurity
*/

if (taxonomy_exists('taxonomy')) {
assertType('bool', taxonomy_exists('taxonomy'));
}
if (! taxonomy_exists('taxonomy')) {
assertType('bool', taxonomy_exists('taxonomy'));
}

$taxonomy = Faker::string();
if (taxonomy_exists($taxonomy)) {
assertType('bool', taxonomy_exists($taxonomy));
}
if (! taxonomy_exists($taxonomy)) {
assertType('bool', taxonomy_exists($taxonomy));
}

/*
* Check type specification
*/

$taxonomy = Faker::string();
if (taxonomy_exists($taxonomy)) {
assertType('non-falsy-string', $taxonomy);
}
if (! taxonomy_exists($taxonomy)) {
assertType('string', $taxonomy);
}
3 changes: 3 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -138187,6 +138187,9 @@ function get_taxonomy($taxonomy)
*
* @param string $taxonomy Name of taxonomy object.
* @return bool Whether the taxonomy exists.
* @phpstan-impure
* @phpstan-assert-if-true =non-falsy-string $taxonomy
* @phpstan-return ($taxonomy is non-falsy-string ? bool : false)
*/
function taxonomy_exists($taxonomy)
{
Expand Down