From 0dbdf5997a219e5c1dd44efb22e814e6f6eb0ba1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 12 Dec 2022 19:37:43 +0000 Subject: [PATCH] Code Modernization: Rename parameters that use reserved keywords in `wp-includes/pomo/po.php`. While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit renames the `$string` parameter to `$input_string` in: * `PO::poify()` * `PO::unpoify()` * `PO::prepend_each_line()` Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #56788. git-svn-id: https://develop.svn.wordpress.org/trunk@54959 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pomo/po.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/pomo/po.php b/src/wp-includes/pomo/po.php index 13fb16eb12..4a61aa8072 100644 --- a/src/wp-includes/pomo/po.php +++ b/src/wp-includes/pomo/po.php @@ -110,10 +110,10 @@ if ( ! class_exists( 'PO', false ) ) : /** * Formats a string in PO-style * - * @param string $string the string to format + * @param string $input_string the string to format * @return string the poified string */ - public static function poify( $string ) { + public static function poify( $input_string ) { $quote = '"'; $slash = '\\'; $newline = "\n"; @@ -124,12 +124,12 @@ if ( ! class_exists( 'PO', false ) ) : "\t" => '\t', ); - $string = str_replace( array_keys( $replaces ), array_values( $replaces ), $string ); + $input_string = str_replace( array_keys( $replaces ), array_values( $replaces ), $input_string ); - $po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $string ) ) . $quote; + $po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $input_string ) ) . $quote; // Add empty string on first line for readbility. - if ( false !== strpos( $string, $newline ) && - ( substr_count( $string, $newline ) > 1 || substr( $string, -strlen( $newline ) ) !== $newline ) ) { + if ( false !== strpos( $input_string, $newline ) && + ( substr_count( $input_string, $newline ) > 1 || substr( $input_string, -strlen( $newline ) ) !== $newline ) ) { $po = "$quote$quote$newline$po"; } // Remove empty strings. @@ -140,17 +140,17 @@ if ( ! class_exists( 'PO', false ) ) : /** * Gives back the original string from a PO-formatted string * - * @param string $string PO-formatted string + * @param string $input_string PO-formatted string * @return string enascaped string */ - public static function unpoify( $string ) { + public static function unpoify( $input_string ) { $escapes = array( 't' => "\t", 'n' => "\n", 'r' => "\r", '\\' => '\\', ); - $lines = array_map( 'trim', explode( "\n", $string ) ); + $lines = array_map( 'trim', explode( "\n", $input_string ) ); $lines = array_map( array( 'PO', 'trim_quotes' ), $lines ); $unpoified = ''; $previous_is_backslash = false; @@ -178,18 +178,18 @@ if ( ! class_exists( 'PO', false ) ) : } /** - * Inserts $with in the beginning of every new line of $string and + * Inserts $with in the beginning of every new line of $input_string and * returns the modified string * - * @param string $string prepend lines in this string - * @param string $with prepend lines with this string + * @param string $input_string prepend lines in this string + * @param string $with prepend lines with this string */ - public static function prepend_each_line( $string, $with ) { - $lines = explode( "\n", $string ); + public static function prepend_each_line( $input_string, $with ) { + $lines = explode( "\n", $input_string ); $append = ''; - if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) { + if ( "\n" === substr( $input_string, -1 ) && '' === end( $lines ) ) { /* - * Last line might be empty because $string was terminated + * Last line might be empty because $input_string was terminated * with a newline, remove it from the $lines array, * we'll restore state by re-terminating the string at the end. */