-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cond. return type for wp_tag_cloud() (#212)
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* Note: | ||
* Starting from PHPStan 1.10.49, void types, including void in unions, are | ||
* transformed into null. | ||
* | ||
* @link https://github.com/phpstan/phpstan-src/pull/2778 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpStubs\WordPress\Core\Tests; | ||
|
||
use function PHPStan\Testing\assertType; | ||
use function wp_tag_cloud; | ||
|
||
// Default value | ||
assertType('null', wp_tag_cloud()); | ||
|
||
// Echo true | ||
assertType('null', wp_tag_cloud(['echo' => true])); | ||
assertType('null', wp_tag_cloud(['format' => 'flat', 'echo' => true])); | ||
assertType('null', wp_tag_cloud(['format' => 'list', 'echo' => true])); | ||
assertType('null', wp_tag_cloud(['format' => 'unexpected', 'echo' => true])); | ||
|
||
// Echo true, but format (maybe) array | ||
assertType('array<int, string>|null', wp_tag_cloud(['format' => 'array', 'echo' => true])); | ||
assertType('array<int, string>|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => true])); | ||
|
||
// Echo false | ||
assertType('string|null', wp_tag_cloud(['echo' => false])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'flat', 'echo' => false])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'list', 'echo' => false])); | ||
assertType('array<int, string>|null', wp_tag_cloud(['format' => 'array', 'echo' => false])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'unexpected', 'echo' => false])); | ||
assertType('array<int, string>|string|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => false])); | ||
|
||
// Echo unknown | ||
/** @var bool|0|1 $echo */ | ||
$boolZeroOne = $_GET['echo']; | ||
|
||
assertType('string|null', wp_tag_cloud(['echo' => $boolZeroOne])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'flat', 'echo' => $boolZeroOne])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'list', 'echo' => $boolZeroOne])); | ||
assertType('array<int, string>|null', wp_tag_cloud(['format' => 'array', 'echo' => $boolZeroOne])); | ||
assertType('string|null', wp_tag_cloud(['format' => 'unexpected', 'echo' => $boolZeroOne])); | ||
assertType('array<int, string>|string|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => $boolZeroOne])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters