From 50d7248e1eac54d1c2d3994cfa6f563c6cbe3741 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 9 Sep 2021 20:38:20 +0000 Subject: [PATCH] Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Image_Editor::save()`. Renames the first parameter in `WP_Image_Editor_GD::save()` to match the parent's method signature. Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match. Adds @since to clearly specify why the change happened. Adds parameter descriptions to parent and both child classes. Follow-up to [22094], [22619], [30681]. Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion. See #51553. git-svn-id: https://develop.svn.wordpress.org/trunk@51790 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-image-editor-gd.php | 10 ++++++---- src/wp-includes/class-wp-image-editor-imagick.php | 4 ++-- src/wp-includes/class-wp-image-editor.php | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index c2105169ec..f175b90d20 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -423,13 +423,15 @@ class WP_Image_Editor_GD extends WP_Image_Editor { * Saves current in-memory image to file. * * @since 3.5.0 + * @since 5.9.0 Renamed `$filename` to `$destfilename` to match parent class + * for PHP 8 named parameter support. * - * @param string|null $filename - * @param string|null $mime_type + * @param string|null $destfilename Optional. Destination filename. Default null. + * @param string|null $mime_type Optional. The mime-type. Default null. * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} */ - public function save( $filename = null, $mime_type = null ) { - $saved = $this->_save( $this->image, $filename, $mime_type ); + public function save( $destfilename = null, $mime_type = null ) { + $saved = $this->_save( $this->image, $destfilename, $mime_type ); if ( ! is_wp_error( $saved ) ) { $this->file = $saved['path']; diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index ae91e46970..b7336fe5ae 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -662,8 +662,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { * * @since 3.5.0 * - * @param string $destfilename - * @param string $mime_type + * @param string $destfilename Optional. Destination filename. Default null. + * @param string $mime_type Optional. The mime-type. Default null. * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} */ public function save( $destfilename = null, $mime_type = null ) { diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index a74d4ac743..b9e580c46f 100644 --- a/src/wp-includes/class-wp-image-editor.php +++ b/src/wp-includes/class-wp-image-editor.php @@ -77,8 +77,8 @@ abstract class WP_Image_Editor { * @since 3.5.0 * @abstract * - * @param string $destfilename - * @param string $mime_type + * @param string $destfilename Optional. Destination filename. Default null. + * @param string $mime_type Optional. The mime-type. Default null. * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} */ abstract public function save( $destfilename = null, $mime_type = null );