-
Notifications
You must be signed in to change notification settings - Fork 65
PHPStan level 9 #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPStan level 9 #286
Changes from 1 commit
b5df0f3
8f60a27
e847909
fac34b3
14895b3
d09bb14
16e7c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
parameters: | ||
level: 9 | ||
paths: | ||
- src | ||
- db-command.php | ||
scanDirectories: | ||
- vendor/wp-cli/wp-cli/php | ||
- vendor/wp-cli/wp-cli-tests | ||
scanFiles: | ||
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php | ||
- tests/phpstan/scan-files.php | ||
treatPhpDocTypesAsCertain: false | ||
dynamicConstantNames: | ||
- DB_HOST | ||
- DB_NAME | ||
- DB_USER | ||
- DB_PASSWORD | ||
- DB_CHARSET | ||
- DB_COLLATE | ||
ignoreErrors: | ||
- identifier: missingType.iterableValue | ||
- identifier: missingType.parameter | ||
- identifier: missingType.return |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,7 @@ | |
|
||
$tables = Utils\wp_get_table_names( | ||
[], | ||
[ 'all-tables-with-prefix' => true ] | ||
); | ||
|
||
foreach ( $tables as $table ) { | ||
|
@@ -260,7 +260,7 @@ | |
|
||
$assoc_args['check'] = true; | ||
self::run( | ||
Utils\esc_cmd( $command, DB_NAME ), | ||
$assoc_args | ||
); | ||
|
||
|
@@ -308,7 +308,7 @@ | |
|
||
$assoc_args['optimize'] = true; | ||
self::run( | ||
Utils\esc_cmd( $command, DB_NAME ), | ||
$assoc_args | ||
); | ||
|
||
|
@@ -356,7 +356,7 @@ | |
|
||
$assoc_args['repair'] = true; | ||
self::run( | ||
Utils\esc_cmd( $command, DB_NAME ), | ||
$assoc_args | ||
); | ||
|
||
|
@@ -409,7 +409,7 @@ | |
} | ||
|
||
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' ); | ||
self::run( $command, $assoc_args, null, true ); | ||
self::run( $command, $assoc_args, false, true ); | ||
} | ||
|
||
/** | ||
|
@@ -634,7 +634,7 @@ | |
$result_file = $args[0]; | ||
} else { | ||
// phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand -- WordPress is not loaded. | ||
$hash = substr( md5( mt_rand() ), 0, 7 ); | ||
$hash = substr( md5( (string) mt_rand() ), 0, 7 ); | ||
$result_file = sprintf( '%s-%s-%s.sql', DB_NAME, date( 'Y-m-d' ), $hash ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | ||
|
||
} | ||
|
@@ -709,7 +709,7 @@ | |
} | ||
} | ||
|
||
$escaped_command = call_user_func_array( '\WP_CLI\Utils\esc_cmd', array_merge( [ $command ], $command_esc_args ) ); | ||
$escaped_command = \WP_CLI\Utils\esc_cmd( $command, $command_esc_args ); | ||
|
||
// Remove parameters not needed for SQL run. | ||
unset( $assoc_args['porcelain'] ); | ||
|
@@ -727,7 +727,7 @@ | |
/** | ||
* Get the current character set of the posts table. | ||
* | ||
* @param array Associative array of associative arguments. | ||
* @param array $assoc_args Associative arguments. | ||
* @return string Posts table character set. | ||
*/ | ||
private function get_posts_table_charset( $assoc_args ) { | ||
|
@@ -891,6 +891,9 @@ | |
* Success: Exported to wordpress_dbase.sql | ||
* | ||
* @when after_wp_load | ||
* | ||
* @param array<string> $args Positional arguments. | ||
* @param array{scope?: string, network?: bool, 'all-tables-with-prefix'?: bool, 'all-tables'?: bool, format: string} $assoc_args Associative arguments. | ||
*/ | ||
public function tables( $args, $assoc_args ) { | ||
|
||
|
@@ -901,7 +904,7 @@ | |
$assoc_args['scope'] = 'all'; | ||
} | ||
|
||
$tables = Utils\wp_get_table_names( $args, $assoc_args ); | ||
|
||
if ( 'csv' === $format ) { | ||
WP_CLI::line( implode( ',', $tables ) ); | ||
|
@@ -1042,6 +1045,9 @@ | |
* 6 | ||
* | ||
* @when after_wp_load | ||
* | ||
* @param array $args Positional arguments. Unused. | ||
* @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. | ||
*/ | ||
public function size( $args, $assoc_args ) { | ||
global $wpdb; | ||
|
@@ -1078,7 +1084,7 @@ | |
if ( $tables || $all_tables || $all_tables_with_prefix ) { | ||
|
||
// Add all of the table sizes. | ||
foreach ( Utils\wp_get_table_names( $args, $assoc_args ) as $table_name ) { | ||
|
||
// Get the table size. | ||
$table_bytes = $wpdb->get_var( | ||
|
@@ -1132,7 +1138,7 @@ | |
// phpcs:enable | ||
|
||
if ( $human_readable ) { | ||
$size_key = floor( log( $row['Size'] ) / log( 1000 ) ); | ||
$size_key = floor( log( (float) $row['Size'] ) / log( 1000 ) ); | ||
$sizes = [ 'B', 'KB', 'MB', 'GB', 'TB' ]; | ||
|
||
$size_format = isset( $sizes[ $size_key ] ) ? $sizes[ $size_key ] : $sizes[0]; | ||
|
@@ -1184,20 +1190,20 @@ | |
} | ||
$size_format_display = preg_replace( '/IB$/u', 'iB', strtoupper( $size_format ) ); | ||
|
||
$decimals = Utils\get_flag_value( $assoc_args, 'decimals', 0 ); | ||
$decimals = (int) Utils\get_flag_value( $assoc_args, 'decimals', 0 ); | ||
$rows[ $index ]['Size'] = round( (int) $row['Bytes'] / $divisor, $decimals ) . ' ' . $size_format_display; | ||
} | ||
} | ||
|
||
if ( ! empty( $size_format ) && ! $tables && ! $format && ! $human_readable && true !== $all_tables && true !== $all_tables_with_prefix ) { | ||
WP_CLI::line( str_replace( " {$size_format_display}", '', $rows[0]['Size'] ) ); | ||
} else { | ||
|
||
// Sort the rows by user input | ||
if ( $orderby ) { | ||
usort( | ||
$rows, | ||
function ( $a, $b ) use ( $order, $orderby ) { | ||
Check failure on line 1206 in src/DB_Command.php
|
||
|
||
$orderby_array = 'asc' === $order ? array( $a, $b ) : array( $b, $a ); | ||
list( $first, $second ) = $orderby_array; | ||
|
@@ -1428,6 +1434,10 @@ | |
$after_context = Utils\get_flag_value( $assoc_args, 'after_context', 40 ); | ||
$after_context = '' === $after_context ? $after_context : (int) $after_context; | ||
|
||
$default_regex_delimiter = false; | ||
$regex_flags = false; | ||
$regex_delimiter = ''; | ||
|
||
$regex = Utils\get_flag_value( $assoc_args, 'regex', false ); | ||
if ( false !== $regex ) { | ||
$regex_flags = Utils\get_flag_value( $assoc_args, 'regex-flags', false ); | ||
|
@@ -1557,7 +1567,7 @@ | |
|
||
// Offsets are in bytes, so need to use `strlen()` and `substr()` before using `safe_substr()`. | ||
if ( $before_context && $offset && ! $append_next ) { | ||
$before = \cli\safe_substr( substr( $col_val, $last_offset, $offset - $last_offset ), -$before_context, null /*length*/, false /*is_width*/, $col_encoding ); | ||
} | ||
if ( $after_context ) { | ||
$end_offset = $offset + strlen( $match ); | ||
|
@@ -1857,7 +1867,7 @@ | |
* Gets the column names of a db table differentiated into key columns and text columns and all columns. | ||
* | ||
* @param string $table The table name. | ||
* @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. | ||
* @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. | ||
*/ | ||
private static function get_columns( $table ) { | ||
global $wpdb; | ||
|
@@ -1890,7 +1900,7 @@ | |
/** | ||
* Determines whether a column is considered text or not. | ||
* | ||
* @param string Column type. | ||
* @param string $type Column type. | ||
* @return bool True if text column, false otherwise. | ||
*/ | ||
private static function is_text_col( $type ) { | ||
|
@@ -1909,6 +1919,8 @@ | |
* | ||
* @param string|array $idents A single identifier or an array of identifiers. | ||
* @return string|array An escaped string if given a string, or an array of escaped strings if given an array of strings. | ||
* | ||
* @phpstan-return ($idents is string ? string : array) | ||
*/ | ||
private static function esc_sql_ident( $idents ) { | ||
$backtick = static function ( $v ) { | ||
|
@@ -2155,11 +2167,6 @@ | |
// Make sure the provided arguments don't interfere with the expected | ||
// output here. | ||
$args = []; | ||
foreach ( [] as $arg ) { | ||
if ( isset( $assoc_args[ $arg ] ) ) { | ||
$args[ $arg ] = $assoc_args[ $arg ]; | ||
} | ||
} | ||
Comment on lines
-2158
to
-2162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looping through an empty array does nothing |
||
|
||
if ( null === $modes ) { | ||
$modes = []; | ||
|
@@ -2183,17 +2190,14 @@ | |
} | ||
|
||
if ( ! empty( $stdout ) ) { | ||
$lines = preg_split( "/\r\n|\n|\r|,/", $stdout ); | ||
$modes = array_filter( | ||
array_map( | ||
'trim', | ||
preg_split( "/\r\n|\n|\r|,/", $stdout ) | ||
$lines ? $lines : [] | ||
) | ||
); | ||
} | ||
|
||
if ( false === $modes ) { | ||
$modes = []; | ||
} | ||
Comment on lines
-2194
to
-2196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was never false |
||
} | ||
|
||
return $modes; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace { | ||
Check failure on line 3 in tests/phpstan/scan-files.php
|
||
define( 'DB_HOST', '' ); | ||
define( 'DB_NAME', '' ); | ||
define( 'DB_USER', '' ); | ||
define( 'DB_PASSWORD', '' ); | ||
define( 'DB_CHARSET', '' ); | ||
define( 'DB_COLLATE', '' ); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.