@@ -409,7 +409,7 @@ public function cli( $_, $assoc_args ) {
409409 }
410410
411411 WP_CLI ::debug ( 'Associative arguments: ' . json_encode ( $ assoc_args ), 'db ' );
412- self ::run ( $ command , $ assoc_args , null , true );
412+ self ::run ( $ command , $ assoc_args , false , true );
413413 }
414414
415415 /**
@@ -634,7 +634,7 @@ public function export( $args, $assoc_args ) {
634634 $ result_file = $ args [0 ];
635635 } else {
636636 // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand -- WordPress is not loaded.
637- $ hash = substr ( md5 ( mt_rand () ), 0 , 7 );
637+ $ hash = substr ( md5 ( ( string ) mt_rand () ), 0 , 7 );
638638 $ result_file = sprintf ( '%s-%s-%s.sql ' , DB_NAME , date ( 'Y-m-d ' ), $ hash ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
639639
640640 }
@@ -709,7 +709,7 @@ public function export( $args, $assoc_args ) {
709709 }
710710 }
711711
712- $ escaped_command = call_user_func_array ( ' \WP_CLI\ Utils\esc_cmd' , array_merge ( [ $ command ], $ command_esc_args ) );
712+ $ escaped_command = Utils \esc_cmd( $ command, ... $ command_esc_args );
713713
714714 // Remove parameters not needed for SQL run.
715715 unset( $ assoc_args ['porcelain ' ] );
@@ -727,7 +727,7 @@ public function export( $args, $assoc_args ) {
727727 /**
728728 * Get the current character set of the posts table.
729729 *
730- * @param array Associative array of associative arguments.
730+ * @param array $assoc_args Associative arguments.
731731 * @return string Posts table character set.
732732 */
733733 private function get_posts_table_charset ( $ assoc_args ) {
@@ -891,6 +891,9 @@ public function import( $args, $assoc_args ) {
891891 * Success: Exported to wordpress_dbase.sql
892892 *
893893 * @when after_wp_load
894+ *
895+ * @param array<string> $args Positional arguments.
896+ * @param array{scope?: string, network?: bool, 'all-tables-with-prefix'?: bool, 'all-tables'?: bool, format: string} $assoc_args Associative arguments.
894897 */
895898 public function tables ( $ args , $ assoc_args ) {
896899
@@ -1042,6 +1045,9 @@ public function tables( $args, $assoc_args ) {
10421045 * 6
10431046 *
10441047 * @when after_wp_load
1048+ *
1049+ * @param array $args Positional arguments. Unused.
1050+ * @param array{size_format?: string, tables?: bool, 'human-readable'?: bool, format?: string, scope?: string, network?: bool, decimals?: string, 'all-tables-with-prefix'?: bool, 'all-tables'?: bool, order: string, orderby: string} $assoc_args Associative arguments.
10451051 */
10461052 public function size ( $ args , $ assoc_args ) {
10471053 global $ wpdb ;
@@ -1114,6 +1120,8 @@ public function size( $args, $assoc_args ) {
11141120 ];
11151121 }
11161122
1123+ $ size_format_display = '' ;
1124+
11171125 if ( ! empty ( $ size_format ) || $ human_readable ) {
11181126 foreach ( $ rows as $ index => $ row ) {
11191127 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Backfilling WP native constants.
@@ -1132,7 +1140,7 @@ public function size( $args, $assoc_args ) {
11321140 // phpcs:enable
11331141
11341142 if ( $ human_readable ) {
1135- $ size_key = floor ( log ( $ row ['Size ' ] ) / log ( 1000 ) );
1143+ $ size_key = floor ( log ( ( float ) $ row ['Size ' ] ) / log ( 1000 ) );
11361144 $ sizes = [ 'B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ];
11371145
11381146 $ size_format = isset ( $ sizes [ $ size_key ] ) ? $ sizes [ $ size_key ] : $ sizes [0 ];
@@ -1184,7 +1192,7 @@ public function size( $args, $assoc_args ) {
11841192 }
11851193 $ size_format_display = preg_replace ( '/IB$/u ' , 'iB ' , strtoupper ( $ size_format ) );
11861194
1187- $ decimals = Utils \get_flag_value ( $ assoc_args , 'decimals ' , 0 );
1195+ $ decimals = ( int ) Utils \get_flag_value ( $ assoc_args , 'decimals ' , 0 );
11881196 $ rows [ $ index ]['Size ' ] = round ( (int ) $ row ['Bytes ' ] / $ divisor , $ decimals ) . ' ' . $ size_format_display ;
11891197 }
11901198 }
@@ -1203,7 +1211,7 @@ function ( $a, $b ) use ( $order, $orderby ) {
12031211 list ( $ first , $ second ) = $ orderby_array ;
12041212
12051213 if ( 'size ' === $ orderby ) {
1206- return $ first ['Bytes ' ] > $ second ['Bytes ' ];
1214+ return $ first ['Bytes ' ] <= > $ second ['Bytes ' ];
12071215 }
12081216
12091217 return strcmp ( $ first ['Name ' ], $ second ['Name ' ] );
@@ -1428,6 +1436,10 @@ public function search( $args, $assoc_args ) {
14281436 $ after_context = Utils \get_flag_value ( $ assoc_args , 'after_context ' , 40 );
14291437 $ after_context = '' === $ after_context ? $ after_context : (int ) $ after_context ;
14301438
1439+ $ default_regex_delimiter = false ;
1440+ $ regex_flags = false ;
1441+ $ regex_delimiter = '' ;
1442+
14311443 $ regex = Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
14321444 if ( false !== $ regex ) {
14331445 $ regex_flags = Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
@@ -1481,7 +1493,7 @@ public function search( $args, $assoc_args ) {
14811493 $ esc_like_search = '% ' . Utils \esc_like ( $ search ) . '% ' ;
14821494 }
14831495
1484- $ encoding = null ;
1496+ $ encoding = false ;
14851497 if ( 0 === strpos ( $ wpdb ->charset , self ::ENCODING_UTF8 ) ) {
14861498 $ encoding = 'UTF-8 ' ;
14871499 }
@@ -1561,7 +1573,7 @@ public function search( $args, $assoc_args ) {
15611573 }
15621574 if ( $ after_context ) {
15631575 $ end_offset = $ offset + strlen ( $ match );
1564- $ after = \cli \safe_substr ( substr ( $ col_val , $ end_offset ), 0 , $ after_context , false /*is_width*/ , $ col_encoding );
1576+ $ after = ( string ) \cli \safe_substr ( substr ( $ col_val , $ end_offset ), 0 , $ after_context , false /*is_width*/ , $ col_encoding );
15651577 // To lessen context duplication in output, shorten the after context if it overlaps with the next match.
15661578 if ( $ i + 1 < $ match_cnt && $ end_offset + strlen ( $ after ) > $ matches [0 ][ $ i + 1 ][1 ] ) {
15671579 $ after = substr ( $ after , 0 , $ matches [0 ][ $ i + 1 ][1 ] - $ end_offset );
@@ -1857,7 +1869,7 @@ private static function get_dbuser_dbpass_args( $assoc_args ) {
18571869 * Gets the column names of a db table differentiated into key columns and text columns and all columns.
18581870 *
18591871 * @param string $table The table name.
1860- * @return array A 3 element array consisting of an array of primary key column names, an array of text column names, and an array containing all column names.
1872+ * @return array{0: string[], 1: string[], 2: string[]} A 3 element array consisting of an array of primary key column names, an array of text column names, and an array containing all column names.
18611873 */
18621874 private static function get_columns ( $ table ) {
18631875 global $ wpdb ;
@@ -1890,7 +1902,7 @@ private static function get_columns( $table ) {
18901902 /**
18911903 * Determines whether a column is considered text or not.
18921904 *
1893- * @param string Column type.
1905+ * @param string $type Column type.
18941906 * @return bool True if text column, false otherwise.
18951907 */
18961908 private static function is_text_col ( $ type ) {
@@ -1909,6 +1921,8 @@ private static function is_text_col( $type ) {
19091921 *
19101922 * @param string|array $idents A single identifier or an array of identifiers.
19111923 * @return string|array An escaped string if given a string, or an array of escaped strings if given an array of strings.
1924+ *
1925+ * @phpstan-return ($idents is string ? string : array)
19121926 */
19131927 private static function esc_sql_ident ( $ idents ) {
19141928 $ backtick = static function ( $ v ) {
@@ -2155,11 +2169,6 @@ protected function get_current_sql_modes( $assoc_args ) {
21552169 // Make sure the provided arguments don't interfere with the expected
21562170 // output here.
21572171 $ args = [];
2158- foreach ( [] as $ arg ) {
2159- if ( isset ( $ assoc_args [ $ arg ] ) ) {
2160- $ args [ $ arg ] = $ assoc_args [ $ arg ];
2161- }
2162- }
21632172
21642173 if ( null === $ modes ) {
21652174 $ modes = [];
@@ -2183,17 +2192,14 @@ protected function get_current_sql_modes( $assoc_args ) {
21832192 }
21842193
21852194 if ( ! empty ( $ stdout ) ) {
2195+ $ lines = preg_split ( "/ \r\n| \n| \r|,/ " , $ stdout );
21862196 $ modes = array_filter (
21872197 array_map (
21882198 'trim ' ,
2189- preg_split ( " / \r\n | \n | \r |,/ " , $ stdout )
2199+ $ lines ? $ lines : []
21902200 )
21912201 );
21922202 }
2193-
2194- if ( false === $ modes ) {
2195- $ modes = [];
2196- }
21972203 }
21982204
21992205 return $ modes ;
0 commit comments