diff --git a/functionMap.php b/functionMap.php index 261912b..d8a3f4d 100644 --- a/functionMap.php +++ b/functionMap.php @@ -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', 'robots' => 'array'], + 'wp_robots_no_robots' => ['array', 'robots' => 'array'], + 'wp_robots_noindex' => ['array', 'robots' => 'array'], + 'wp_robots_noindex_embeds' => ['array', 'robots' => 'array'], + 'wp_robots_noindex_search' => ['array', 'robots' => 'array'], + 'wp_robots_sensitive_page' => ['array', 'robots' => 'array'], 'wp_safe_remote_get' => [$httpReturnType], 'wp_safe_remote_head' => [$httpReturnType], 'wp_safe_remote_post' => [$httpReturnType], diff --git a/phpcs.xml.dist b/phpcs.xml.dist index bbdcc44..5d7c26f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,6 +18,7 @@ tests/data/param/wpdb.php + tests/data/param/wp-robots.php tests/data/param/absint.php diff --git a/tests/ParameterTypeTest.php b/tests/ParameterTypeTest.php index 2b5aee8..a926264 100644 --- a/tests/ParameterTypeTest.php +++ b/tests/ParameterTypeTest.php @@ -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( @@ -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( @@ -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, array given.', 16], + ['Parameter #1 $robots of function wp_robots_no_robots expects array, array given.', 17], + ['Parameter #1 $robots of function wp_robots_noindex expects array, array given.', 18], + ['Parameter #1 $robots of function wp_robots_noindex_embeds expects array, array given.', 19], + ['Parameter #1 $robots of function wp_robots_noindex_search expects array, array given.', 20], + ['Parameter #1 $robots of function wp_robots_sensitive_page expects array, array given.', 21], + ] + ); + } + public function testWpTriggerError(): void { $this->analyse( diff --git a/tests/data/param/wp-robots.php b/tests/data/param/wp-robots.php new file mode 100644 index 0000000..7801ac6 --- /dev/null +++ b/tests/data/param/wp-robots.php @@ -0,0 +1,30 @@ + +$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 +$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); diff --git a/tests/data/return/wp-robots.php b/tests/data/return/wp-robots.php new file mode 100644 index 0000000..35c6560 --- /dev/null +++ b/tests/data/return/wp-robots.php @@ -0,0 +1,20 @@ +', wp_robots_max_image_preview_large(Faker::array())); +assertType('array', wp_robots_no_robots(Faker::array())); +assertType('array', wp_robots_noindex(Faker::array())); +assertType('array', wp_robots_noindex_embeds(Faker::array())); +assertType('array', wp_robots_noindex_search(Faker::array())); +assertType('array', wp_robots_sensitive_page(Faker::array())); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 402979b..5a54747 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -136666,6 +136666,8 @@ function wp_robots() * * @param array $robots Associative array of robots directives. * @return array Filtered robots directives. + * @phpstan-param array $robots + * @phpstan-return array */ function wp_robots_noindex(array $robots) { @@ -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 $robots + * @phpstan-return array */ function wp_robots_noindex_embeds(array $robots) { @@ -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 $robots + * @phpstan-return array */ function wp_robots_noindex_search(array $robots) { @@ -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 $robots + * @phpstan-return array */ function wp_robots_no_robots(array $robots) { @@ -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 $robots + * @phpstan-return array */ function wp_robots_sensitive_page(array $robots) { @@ -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 $robots + * @phpstan-return array */ function wp_robots_max_image_preview_large(array $robots) {