Make WordPress Core

Changeset 54959


Ignore:
Timestamp:
12/12/2022 07:37:43 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pomo/po.php

    r54134 r54959  
    111111         * Formats a string in PO-style
    112112         *
    113          * @param string $string the string to format
     113         * @param string $input_string the string to format
    114114         * @return string the poified string
    115115         */
    116         public static function poify( $string ) {
     116        public static function poify( $input_string ) {
    117117            $quote   = '"';
    118118            $slash   = '\\';
     
    125125            );
    126126
    127             $string = str_replace( array_keys( $replaces ), array_values( $replaces ), $string );
    128 
    129             $po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $string ) ) . $quote;
     127            $input_string = str_replace( array_keys( $replaces ), array_values( $replaces ), $input_string );
     128
     129            $po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $input_string ) ) . $quote;
    130130            // Add empty string on first line for readbility.
    131             if ( false !== strpos( $string, $newline ) &&
    132                 ( substr_count( $string, $newline ) > 1 || substr( $string, -strlen( $newline ) ) !== $newline ) ) {
     131            if ( false !== strpos( $input_string, $newline ) &&
     132                ( substr_count( $input_string, $newline ) > 1 || substr( $input_string, -strlen( $newline ) ) !== $newline ) ) {
    133133                $po = "$quote$quote$newline$po";
    134134            }
     
    141141         * Gives back the original string from a PO-formatted string
    142142         *
    143          * @param string $string PO-formatted string
     143         * @param string $input_string PO-formatted string
    144144         * @return string enascaped string
    145145         */
    146         public static function unpoify( $string ) {
     146        public static function unpoify( $input_string ) {
    147147            $escapes               = array(
    148148                't'  => "\t",
     
    151151                '\\' => '\\',
    152152            );
    153             $lines                 = array_map( 'trim', explode( "\n", $string ) );
     153            $lines                 = array_map( 'trim', explode( "\n", $input_string ) );
    154154            $lines                 = array_map( array( 'PO', 'trim_quotes' ), $lines );
    155155            $unpoified             = '';
     
    179179
    180180        /**
    181          * Inserts $with in the beginning of every new line of $string and
     181         * Inserts $with in the beginning of every new line of $input_string and
    182182         * returns the modified string
    183183         *
    184          * @param string $string prepend lines in this string
    185          * @param string $with prepend lines with this string
    186          */
    187         public static function prepend_each_line( $string, $with ) {
    188             $lines  = explode( "\n", $string );
     184         * @param string $input_string prepend lines in this string
     185         * @param string $with         prepend lines with this string
     186         */
     187        public static function prepend_each_line( $input_string, $with ) {
     188            $lines  = explode( "\n", $input_string );
    189189            $append = '';
    190             if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) {
     190            if ( "\n" === substr( $input_string, -1 ) && '' === end( $lines ) ) {
    191191                /*
    192                  * Last line might be empty because $string was terminated
     192                 * Last line might be empty because $input_string was terminated
    193193                 * with a newline, remove it from the $lines array,
    194194                 * we'll restore state by re-terminating the string at the end.
Note: See TracChangeset for help on using the changeset viewer.