Skip to content
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

Update PHPStan level to 8 #1210

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/server-timing/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static function ( string $hook_name ): string {
* restricted to them, therefore the sanitization does not limit the characters
* used.
*/
return preg_replace(
return (string) preg_replace(
'/\s/',
'',
sanitize_text_field( $hook_name )
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 7
level: 8
treatPhpDocTypesAsCertain: false
paths:
- load.php
Expand Down
3 changes: 3 additions & 0 deletions plugins/optimization-detective/class-od-html-tag-walker.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public function open_tags(): Generator {
$this->open_stack_indices = array();
while ( $p->next_tag( array( 'tag_closers' => 'visit' ) ) ) {
$tag_name = $p->get_tag();
if ( ! is_string( $tag_name ) ) {
continue;
}
if ( ! $p->is_tag_closer() ) {

// Close an open P tag when a P-closing tag is encountered.
Expand Down
2 changes: 1 addition & 1 deletion plugins/webp-uploads/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ function webp_uploads_wepb_fallback(): void {
$javascript = ob_get_clean();

wp_print_inline_script_tag(
preg_replace( '/\s+/', '', (string) $javascript ),
(string) preg_replace( '/\s+/', '', (string) $javascript ),
array(
'id' => 'webpUploadsFallbackWebpImages',
'data-rest-api' => esc_url_raw( trailingslashit( get_rest_url() ) ),
Expand Down
20 changes: 12 additions & 8 deletions plugins/webp-uploads/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_t
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$target = isset( $_REQUEST['target'] ) ? sanitize_key( $_REQUEST['target'] ) : 'all';

foreach ( $old_metadata['sizes'] as $size_name => $size_details ) {
// If the target is 'nothumb', skip generating the 'thumbnail' size.
if ( webp_uploads_image_edit_thumbnails_separately() && 'nothumb' === $target && 'thumbnail' === $size_name ) {
continue;
}
if ( isset( $old_metadata['sizes'] ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inclusion of this if statement wrapper is the only change to this block of code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turning off whitespace confirms this

foreach ( $old_metadata['sizes'] as $size_name => $size_details ) {
// If the target is 'nothumb', skip generating the 'thumbnail' size.
if ( webp_uploads_image_edit_thumbnails_separately() && 'nothumb' === $target && 'thumbnail' === $size_name ) {
continue;
}

if ( isset( $metadata['sizes'][ $size_name ] ) && ! empty( $metadata['sizes'][ $size_name ] ) &&
$metadata['sizes'][ $size_name ]['file'] !== $old_metadata['sizes'][ $size_name ]['file'] ) {
$resize_sizes[ $size_name ] = $metadata['sizes'][ $size_name ];
if (
isset( $metadata['sizes'][ $size_name ] ) && ! empty( $metadata['sizes'][ $size_name ] ) &&
$metadata['sizes'][ $size_name ]['file'] !== $old_metadata['sizes'][ $size_name ]['file']
) {
$resize_sizes[ $size_name ] = $metadata['sizes'][ $size_name ];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public function test_html_tag_processor_wrapper_methods(): void {
* @return string Snapshot.
*/
private function export_array_snapshot( array $data, bool $one_line = false ): string {
$php = preg_replace( '/^\s*\d+\s*=>\s*/m', '', var_export( $data, true ) );
$php = (string) preg_replace( '/^\s*\d+\s*=>\s*/m', '', var_export( $data, true ) );
if ( $one_line ) {
$php = str_replace( "\n", ' ', $php );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/optimization-detective/optimization-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ public function test_od_optimize_template_output_buffer( Closure $set_up, string
$set_up();

$remove_initial_tabs = static function ( string $input ): string {
return preg_replace( '/^\t+/m', '', $input );
return (string) preg_replace( '/^\t+/m', '', $input );
};

$expected = $remove_initial_tabs( $expected );
Expand All @@ -1134,7 +1134,7 @@ public function test_od_optimize_template_output_buffer( Closure $set_up, string
* @return string Normalized string.
*/
private function normalize_whitespace( string $str ): string {
return preg_replace( '/\s+/', ' ', trim( $str ) );
return (string) preg_replace( '/\s+/', ' ', trim( $str ) );
}

/**
Expand Down
Loading