Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105978 additions and 78184 deletions
+29 -24
View File
@@ -12,12 +12,12 @@
* @since 3.5.0
*/
abstract class WP_Image_Editor {
protected $file = null;
protected $size = null;
protected $mime_type = null;
protected $file = null;
protected $size = null;
protected $mime_type = null;
protected $default_mime_type = 'image/jpeg';
protected $quality = false;
protected $default_quality = 82;
protected $quality = false;
protected $default_quality = 82;
/**
* Each instance handles a single file.
@@ -191,8 +191,8 @@ abstract class WP_Image_Editor {
*/
protected function update_size( $width = null, $height = null ) {
$this->size = array(
'width' => (int) $width,
'height' => (int) $height
'width' => (int) $width,
'height' => (int) $height,
);
return true;
}
@@ -271,7 +271,7 @@ abstract class WP_Image_Editor {
$this->quality = $quality;
return true;
} else {
return new WP_Error( 'invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].') );
return new WP_Error( 'invalid_image_quality', __( 'Attempted to set image quality outside of the range [1,100].' ) );
}
}
@@ -298,12 +298,11 @@ abstract class WP_Image_Editor {
}
if ( $filename ) {
$file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
$file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
$file_mime = $this->get_mime_type( $file_ext );
}
else {
} else {
// If no file specified, grab editor's current extension and mime-type.
$file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
$file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
$file_mime = $this->mime_type;
}
@@ -311,7 +310,7 @@ abstract class WP_Image_Editor {
// file extension. If so, prefer extension from file.
if ( ! $mime_type || ( $file_mime == $mime_type ) ) {
$mime_type = $file_mime;
$new_ext = $file_ext;
$new_ext = $file_ext;
}
// Double-check that the mime-type selected is supported by the editor.
@@ -327,7 +326,7 @@ abstract class WP_Image_Editor {
* @param string $mime_type Mime type string.
*/
$mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type );
$new_ext = $this->get_extension( $mime_type );
$new_ext = $this->get_extension( $mime_type );
}
if ( $filename ) {
@@ -352,17 +351,19 @@ abstract class WP_Image_Editor {
*/
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
// $suffix will be appended to the destination filename, just before the extension
if ( ! $suffix )
if ( ! $suffix ) {
$suffix = $this->get_suffix();
}
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
$name = wp_basename( $this->file, ".$ext" );
$name = wp_basename( $this->file, ".$ext" );
$new_ext = strtolower( $extension ? $extension : $ext );
if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) )
if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) {
$dir = $_dest_path;
}
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
}
@@ -375,8 +376,9 @@ abstract class WP_Image_Editor {
* @return false|string suffix
*/
public function get_suffix() {
if ( ! $this->get_size() )
if ( ! $this->get_size() ) {
return false;
}
return "{$this->size['width']}x{$this->size['height']}";
}
@@ -406,8 +408,9 @@ abstract class WP_Image_Editor {
$fp = fopen( $filename, 'w' );
if ( ! $fp )
if ( ! $fp ) {
return false;
}
fwrite( $fp, $contents );
fclose( $fp );
@@ -432,15 +435,16 @@ abstract class WP_Image_Editor {
* @return string|false
*/
protected static function get_mime_type( $extension = null ) {
if ( ! $extension )
if ( ! $extension ) {
return false;
}
$mime_types = wp_get_mime_types();
$extensions = array_keys( $mime_types );
foreach ( $extensions as $_extension ) {
if ( preg_match( "/{$extension}/i", $_extension ) ) {
return $mime_types[$_extension];
return $mime_types[ $_extension ];
}
}
@@ -461,8 +465,9 @@ abstract class WP_Image_Editor {
protected static function get_extension( $mime_type = null ) {
$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) );
if ( empty( $extensions[0] ) )
if ( empty( $extensions[0] ) ) {
return false;
}
return $extensions[0];
}