@@ -409,7 +409,7 @@ public function cli( $_, $assoc_args ) {
409
409
}
410
410
411
411
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 );
413
413
}
414
414
415
415
/**
@@ -634,7 +634,7 @@ public function export( $args, $assoc_args ) {
634
634
$ result_file = $ args [0 ];
635
635
} else {
636
636
// 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 );
638
638
$ result_file = sprintf ( '%s-%s-%s.sql ' , DB_NAME , date ( 'Y-m-d ' ), $ hash ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
639
639
640
640
}
@@ -709,7 +709,7 @@ public function export( $args, $assoc_args ) {
709
709
}
710
710
}
711
711
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 );
713
713
714
714
// Remove parameters not needed for SQL run.
715
715
unset( $ assoc_args ['porcelain ' ] );
@@ -727,7 +727,7 @@ public function export( $args, $assoc_args ) {
727
727
/**
728
728
* Get the current character set of the posts table.
729
729
*
730
- * @param array Associative array of associative arguments.
730
+ * @param array $assoc_args Associative arguments.
731
731
* @return string Posts table character set.
732
732
*/
733
733
private function get_posts_table_charset ( $ assoc_args ) {
@@ -891,6 +891,9 @@ public function import( $args, $assoc_args ) {
891
891
* Success: Exported to wordpress_dbase.sql
892
892
*
893
893
* @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.
894
897
*/
895
898
public function tables ( $ args , $ assoc_args ) {
896
899
@@ -1042,6 +1045,9 @@ public function tables( $args, $assoc_args ) {
1042
1045
* 6
1043
1046
*
1044
1047
* @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.
1045
1051
*/
1046
1052
public function size ( $ args , $ assoc_args ) {
1047
1053
global $ wpdb ;
@@ -1114,6 +1120,8 @@ public function size( $args, $assoc_args ) {
1114
1120
];
1115
1121
}
1116
1122
1123
+ $ size_format_display = '' ;
1124
+
1117
1125
if ( ! empty ( $ size_format ) || $ human_readable ) {
1118
1126
foreach ( $ rows as $ index => $ row ) {
1119
1127
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Backfilling WP native constants.
@@ -1132,7 +1140,7 @@ public function size( $args, $assoc_args ) {
1132
1140
// phpcs:enable
1133
1141
1134
1142
if ( $ human_readable ) {
1135
- $ size_key = floor ( log ( $ row ['Size ' ] ) / log ( 1000 ) );
1143
+ $ size_key = floor ( log ( ( float ) $ row ['Size ' ] ) / log ( 1000 ) );
1136
1144
$ sizes = [ 'B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ];
1137
1145
1138
1146
$ size_format = isset ( $ sizes [ $ size_key ] ) ? $ sizes [ $ size_key ] : $ sizes [0 ];
@@ -1184,7 +1192,7 @@ public function size( $args, $assoc_args ) {
1184
1192
}
1185
1193
$ size_format_display = preg_replace ( '/IB$/u ' , 'iB ' , strtoupper ( $ size_format ) );
1186
1194
1187
- $ decimals = Utils \get_flag_value ( $ assoc_args , 'decimals ' , 0 );
1195
+ $ decimals = ( int ) Utils \get_flag_value ( $ assoc_args , 'decimals ' , 0 );
1188
1196
$ rows [ $ index ]['Size ' ] = round ( (int ) $ row ['Bytes ' ] / $ divisor , $ decimals ) . ' ' . $ size_format_display ;
1189
1197
}
1190
1198
}
@@ -1203,7 +1211,7 @@ function ( $a, $b ) use ( $order, $orderby ) {
1203
1211
list ( $ first , $ second ) = $ orderby_array ;
1204
1212
1205
1213
if ( 'size ' === $ orderby ) {
1206
- return $ first ['Bytes ' ] > $ second ['Bytes ' ];
1214
+ return $ first ['Bytes ' ] <= > $ second ['Bytes ' ];
1207
1215
}
1208
1216
1209
1217
return strcmp ( $ first ['Name ' ], $ second ['Name ' ] );
@@ -1428,6 +1436,10 @@ public function search( $args, $assoc_args ) {
1428
1436
$ after_context = Utils \get_flag_value ( $ assoc_args , 'after_context ' , 40 );
1429
1437
$ after_context = '' === $ after_context ? $ after_context : (int ) $ after_context ;
1430
1438
1439
+ $ default_regex_delimiter = false ;
1440
+ $ regex_flags = false ;
1441
+ $ regex_delimiter = '' ;
1442
+
1431
1443
$ regex = Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
1432
1444
if ( false !== $ regex ) {
1433
1445
$ regex_flags = Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
@@ -1481,7 +1493,7 @@ public function search( $args, $assoc_args ) {
1481
1493
$ esc_like_search = '% ' . Utils \esc_like ( $ search ) . '% ' ;
1482
1494
}
1483
1495
1484
- $ encoding = null ;
1496
+ $ encoding = false ;
1485
1497
if ( 0 === strpos ( $ wpdb ->charset , self ::ENCODING_UTF8 ) ) {
1486
1498
$ encoding = 'UTF-8 ' ;
1487
1499
}
@@ -1561,7 +1573,7 @@ public function search( $args, $assoc_args ) {
1561
1573
}
1562
1574
if ( $ after_context ) {
1563
1575
$ 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 );
1565
1577
// To lessen context duplication in output, shorten the after context if it overlaps with the next match.
1566
1578
if ( $ i + 1 < $ match_cnt && $ end_offset + strlen ( $ after ) > $ matches [0 ][ $ i + 1 ][1 ] ) {
1567
1579
$ after = substr ( $ after , 0 , $ matches [0 ][ $ i + 1 ][1 ] - $ end_offset );
@@ -1857,7 +1869,7 @@ private static function get_dbuser_dbpass_args( $assoc_args ) {
1857
1869
* Gets the column names of a db table differentiated into key columns and text columns and all columns.
1858
1870
*
1859
1871
* @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.
1861
1873
*/
1862
1874
private static function get_columns ( $ table ) {
1863
1875
global $ wpdb ;
@@ -1890,7 +1902,7 @@ private static function get_columns( $table ) {
1890
1902
/**
1891
1903
* Determines whether a column is considered text or not.
1892
1904
*
1893
- * @param string Column type.
1905
+ * @param string $type Column type.
1894
1906
* @return bool True if text column, false otherwise.
1895
1907
*/
1896
1908
private static function is_text_col ( $ type ) {
@@ -1909,6 +1921,8 @@ private static function is_text_col( $type ) {
1909
1921
*
1910
1922
* @param string|array $idents A single identifier or an array of identifiers.
1911
1923
* @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)
1912
1926
*/
1913
1927
private static function esc_sql_ident ( $ idents ) {
1914
1928
$ backtick = static function ( $ v ) {
@@ -2155,11 +2169,6 @@ protected function get_current_sql_modes( $assoc_args ) {
2155
2169
// Make sure the provided arguments don't interfere with the expected
2156
2170
// output here.
2157
2171
$ args = [];
2158
- foreach ( [] as $ arg ) {
2159
- if ( isset ( $ assoc_args [ $ arg ] ) ) {
2160
- $ args [ $ arg ] = $ assoc_args [ $ arg ];
2161
- }
2162
- }
2163
2172
2164
2173
if ( null === $ modes ) {
2165
2174
$ modes = [];
@@ -2183,17 +2192,14 @@ protected function get_current_sql_modes( $assoc_args ) {
2183
2192
}
2184
2193
2185
2194
if ( ! empty ( $ stdout ) ) {
2195
+ $ lines = preg_split ( "/ \r\n| \n| \r|,/ " , $ stdout );
2186
2196
$ modes = array_filter (
2187
2197
array_map (
2188
2198
'trim ' ,
2189
- preg_split ( " / \r\n | \n | \r |,/ " , $ stdout )
2199
+ $ lines ? $ lines : []
2190
2200
)
2191
2201
);
2192
2202
}
2193
-
2194
- if ( false === $ modes ) {
2195
- $ modes = [];
2196
- }
2197
2203
}
2198
2204
2199
2205
return $ modes ;
0 commit comments