Skip to content

Commit 20de6d8

Browse files
committed
Docs: Improve specificity of PHP types in functions.wp-scripts.php and functions.wp-styles.php.
These files now adhere to PHPStan level 8. Developed in #10652 Follow-up to [61362], [61358]. See #64238. git-svn-id: https://develop.svn.wordpress.org/trunk@61402 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5f7cef7 commit 20de6d8

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/wp-includes/functions.wp-scripts.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) {
141141
),
142142
'4.5.0'
143143
);
144-
$data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
144+
$data = trim( (string) preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
145145
}
146146

147147
return wp_scripts()->add_inline_script( $handle, $data, $position );
@@ -160,15 +160,15 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) {
160160
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
161161
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
162162
*
163-
* @param string $handle Name of the script. Should be unique.
164-
* @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory.
165-
* If source is set to false, script is an alias of other scripts it depends on.
166-
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
167-
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
168-
* as a query string for cache busting purposes. If version is set to false, a version
169-
* number is automatically added equal to current installed WordPress version.
170-
* If set to null, no version is added.
171-
* @param array|bool $args {
163+
* @param string $handle Name of the script. Should be unique.
164+
* @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory.
165+
* If source is set to false, script is an alias of other scripts it depends on.
166+
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
167+
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
168+
* as a query string for cache busting purposes. If version is set to false, a version
169+
* number is automatically added equal to current installed WordPress version.
170+
* If set to null, no version is added.
171+
* @param array<string, string|bool>|bool $args {
172172
* Optional. An array of additional script loading strategies. Default empty array.
173173
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
174174
*
@@ -221,10 +221,10 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args
221221
*
222222
* @todo Documentation cleanup
223223
*
224-
* @param string $handle Script handle the data will be attached to.
225-
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
226-
* Example: '/[a-zA-Z0-9_]+/'.
227-
* @param array $l10n The data itself. The data can be either a single or multi-dimensional array.
224+
* @param string $handle Script handle the data will be attached to.
225+
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
226+
* Example: '/[a-zA-Z0-9_]+/'.
227+
* @param array<string, mixed> $l10n The data itself. The data can be either a single or multi-dimensional array.
228228
* @return bool True if the script was successfully localized, false otherwise.
229229
*/
230230
function wp_localize_script( $handle, $object_name, $l10n ) {
@@ -346,15 +346,15 @@ function wp_deregister_script( $handle ) {
346346
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
347347
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array.
348348
*
349-
* @param string $handle Name of the script. Should be unique.
350-
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
351-
* Default empty.
352-
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
353-
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
354-
* as a query string for cache busting purposes. If version is set to false, a version
355-
* number is automatically added equal to current installed WordPress version.
356-
* If set to null, no version is added.
357-
* @param array|bool $args {
349+
* @param string $handle Name of the script. Should be unique.
350+
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
351+
* Default empty.
352+
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
353+
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
354+
* as a query string for cache busting purposes. If version is set to false, a version
355+
* number is automatically added equal to current installed WordPress version.
356+
* If set to null, no version is added.
357+
* @param array<string, string|bool>|bool $args {
358358
* Optional. An array of additional script loading strategies. Default empty array.
359359
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
360360
*

src/wp-includes/functions.wp-styles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function wp_styles() {
3838
*
3939
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
4040
*
41-
* @param string|bool|array $handles Styles to be printed. Default 'false'.
41+
* @param string|false|string[] $handles Styles to be printed. Default 'false'.
4242
* @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
4343
*/
4444
function wp_print_styles( $handles = false ) {
@@ -98,7 +98,7 @@ function wp_add_inline_style( $handle, $data ) {
9898
),
9999
'3.7.0'
100100
);
101-
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
101+
$data = trim( (string) preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
102102
}
103103

104104
return wp_styles()->add_inline_style( $handle, $data );

0 commit comments

Comments
 (0)