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
6 changes: 6 additions & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@
'wp_remote_post' => [$httpReturnType],
'wp_remote_request' => [$httpReturnType],
'wp_reschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType],
'wp_robots_max_image_preview_large' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_robots_no_robots' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_robots_noindex' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_robots_noindex_embeds' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_robots_noindex_search' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_robots_sensitive_page' => ['array<string, bool|string>', 'robots' => 'array<string, bool|string>'],
'wp_safe_remote_get' => [$httpReturnType],
'wp_safe_remote_head' => [$httpReturnType],
'wp_safe_remote_post' => [$httpReturnType],
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</rule>
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable">
<exclude-pattern>tests/data/param/wpdb.php</exclude-pattern>
<exclude-pattern>tests/data/param/wp-robots.php</exclude-pattern>
<exclude-pattern>tests/data/param/absint.php</exclude-pattern>
</rule>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
Expand Down
45 changes: 30 additions & 15 deletions tests/ParameterTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public function testCheckAjaxReferer(): void
);
}

public function testDoAction(): void
{
$this->analyse(
__DIR__ . '/data/param/do-action.php',
[
["Parameter #1 \$hook_name of function do_action expects non-empty-string, '' given.", 8],
["Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, '' given.", 9],
["Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, '' given.", 10],
['Parameter #1 $hook_name of function do_action expects non-empty-string, string given.', 13],
['Parameter #1 $hook_name of function do_action_ref_array expects non-empty-string, string given.', 14],
['Parameter #1 $hook_name of function do_action_deprecated expects non-empty-string, string given.', 15],
]
);
}

public function testRegisterActivationHook(): void
{
$this->analyse(
Expand All @@ -177,21 +192,6 @@ public function testRegisterDeactivationHook(): void
);
}

public function testDoAction(): void
{
$this->analyse(
__DIR__ . '/data/param/do-action.php',
[
["Parameter #1 \$hook_name of function do_action expects non-empty-string, '' given.", 8],
["Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, '' given.", 9],
["Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, '' given.", 10],
['Parameter #1 $hook_name of function do_action expects non-empty-string, string given.', 13],
['Parameter #1 $hook_name of function do_action_ref_array expects non-empty-string, string given.', 14],
['Parameter #1 $hook_name of function do_action_deprecated expects non-empty-string, string given.', 15],
]
);
}

public function testRegisterNavMenus(): void
{
$this->analyse(
Expand Down Expand Up @@ -246,6 +246,21 @@ public function testWpdbGetRow(): void
);
}

public function testWpRobots(): void
{
$this->analyse(
__DIR__ . '/data/param/wp-robots.php',
[
['Parameter #1 $robots of function wp_robots_max_image_preview_large expects array<string, bool|string>, array<string, int> given.', 16],
['Parameter #1 $robots of function wp_robots_no_robots expects array<string, bool|string>, array<string, int> given.', 17],
['Parameter #1 $robots of function wp_robots_noindex expects array<string, bool|string>, array<string, int> given.', 18],
['Parameter #1 $robots of function wp_robots_noindex_embeds expects array<string, bool|string>, array<string, int> given.', 19],
['Parameter #1 $robots of function wp_robots_noindex_search expects array<string, bool|string>, array<string, int> given.', 20],
['Parameter #1 $robots of function wp_robots_sensitive_page expects array<string, bool|string>, array<string, int> given.', 21],
]
);
}

public function testWpTriggerError(): void
{
$this->analyse(
Expand Down
30 changes: 30 additions & 0 deletions tests/data/param/wp-robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function wp_robots_max_image_preview_large;
use function wp_robots_no_robots;
use function wp_robots_noindex;
use function wp_robots_noindex_embeds;
use function wp_robots_noindex_search;
use function wp_robots_sensitive_page;

// Incorrect usages with array<string, int>
$incorrect = Faker::strArray(Faker::int());
$robots = wp_robots_max_image_preview_large($incorrect);
$robots = wp_robots_no_robots($incorrect);
$robots = wp_robots_noindex($incorrect);
$robots = wp_robots_noindex_embeds($incorrect);
$robots = wp_robots_noindex_search($incorrect);
$robots = wp_robots_sensitive_page($incorrect);

// Correct usages with array<string, string>
$correct = Faker::strArray(Faker::string());
$robots = wp_robots_max_image_preview_large($correct);
$robots = wp_robots_no_robots($correct);
$robots = wp_robots_noindex($correct);
$robots = wp_robots_noindex_embeds($correct);
$robots = wp_robots_noindex_search($correct);
$robots = wp_robots_sensitive_page($correct);
20 changes: 20 additions & 0 deletions tests/data/return/wp-robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function wp_robots_max_image_preview_large;
use function wp_robots_no_robots;
use function wp_robots_noindex;
use function wp_robots_noindex_embeds;
use function wp_robots_noindex_search;
use function wp_robots_sensitive_page;
use function PHPStan\Testing\assertType;

assertType('array<string, bool|string>', wp_robots_max_image_preview_large(Faker::array()));
assertType('array<string, bool|string>', wp_robots_no_robots(Faker::array()));
assertType('array<string, bool|string>', wp_robots_noindex(Faker::array()));
assertType('array<string, bool|string>', wp_robots_noindex_embeds(Faker::array()));
assertType('array<string, bool|string>', wp_robots_noindex_search(Faker::array()));
assertType('array<string, bool|string>', wp_robots_sensitive_page(Faker::array()));
12 changes: 12 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -136666,6 +136666,8 @@ function wp_robots()
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_noindex(array $robots)
{
Expand All @@ -136683,6 +136685,8 @@ function wp_robots_noindex(array $robots)
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_noindex_embeds(array $robots)
{
Expand All @@ -136704,6 +136708,8 @@ function wp_robots_noindex_embeds(array $robots)
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_noindex_search(array $robots)
{
Expand All @@ -136721,6 +136727,8 @@ function wp_robots_noindex_search(array $robots)
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_no_robots(array $robots)
{
Expand All @@ -136739,6 +136747,8 @@ function wp_robots_no_robots(array $robots)
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_sensitive_page(array $robots)
{
Expand All @@ -136757,6 +136767,8 @@ function wp_robots_sensitive_page(array $robots)
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
* @phpstan-param array<string, bool|string> $robots
* @phpstan-return array<string, bool|string>
*/
function wp_robots_max_image_preview_large(array $robots)
{
Expand Down