Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor.php

    r41288 r42343  
    1313 */
    1414abstract class WP_Image_Editor {
    15     protected $file = null;
    16     protected $size = null;
    17     protected $mime_type = null;
     15    protected $file              = null;
     16    protected $size              = null;
     17    protected $mime_type         = null;
    1818    protected $default_mime_type = 'image/jpeg';
    19     protected $quality = false;
    20     protected $default_quality = 82;
     19    protected $quality           = false;
     20    protected $default_quality   = 82;
    2121
    2222    /**
     
    192192    protected function update_size( $width = null, $height = null ) {
    193193        $this->size = array(
    194             'width' => (int) $width,
    195             'height' => (int) $height
     194            'width'  => (int) $width,
     195            'height' => (int) $height,
    196196        );
    197197        return true;
     
    272272            return true;
    273273        } else {
    274             return new WP_Error( 'invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].') );
     274            return new WP_Error( 'invalid_image_quality', __( 'Attempted to set image quality outside of the range [1,100].' ) );
    275275        }
    276276    }
     
    299299
    300300        if ( $filename ) {
    301             $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
     301            $file_ext  = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
    302302            $file_mime = $this->get_mime_type( $file_ext );
    303         }
    304         else {
     303        } else {
    305304            // If no file specified, grab editor's current extension and mime-type.
    306             $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
     305            $file_ext  = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
    307306            $file_mime = $this->mime_type;
    308307        }
     
    312311        if ( ! $mime_type || ( $file_mime == $mime_type ) ) {
    313312            $mime_type = $file_mime;
    314             $new_ext = $file_ext;
     313            $new_ext   = $file_ext;
    315314        }
    316315
     
    328327             */
    329328            $mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type );
    330             $new_ext = $this->get_extension( $mime_type );
     329            $new_ext   = $this->get_extension( $mime_type );
    331330        }
    332331
     
    353352    public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
    354353        // $suffix will be appended to the destination filename, just before the extension
    355         if ( ! $suffix )
     354        if ( ! $suffix ) {
    356355            $suffix = $this->get_suffix();
    357 
    358         $dir  = pathinfo( $this->file, PATHINFO_DIRNAME );
    359         $ext  = pathinfo( $this->file, PATHINFO_EXTENSION );
    360 
    361         $name = wp_basename( $this->file, ".$ext" );
     356        }
     357
     358        $dir = pathinfo( $this->file, PATHINFO_DIRNAME );
     359        $ext = pathinfo( $this->file, PATHINFO_EXTENSION );
     360
     361        $name    = wp_basename( $this->file, ".$ext" );
    362362        $new_ext = strtolower( $extension ? $extension : $ext );
    363363
    364         if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) )
     364        if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) {
    365365            $dir = $_dest_path;
     366        }
    366367
    367368        return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
     
    376377     */
    377378    public function get_suffix() {
    378         if ( ! $this->get_size() )
     379        if ( ! $this->get_size() ) {
    379380            return false;
     381        }
    380382
    381383        return "{$this->size['width']}x{$this->size['height']}";
     
    407409            $fp = fopen( $filename, 'w' );
    408410
    409             if ( ! $fp )
     411            if ( ! $fp ) {
    410412                return false;
     413            }
    411414
    412415            fwrite( $fp, $contents );
     
    433436     */
    434437    protected static function get_mime_type( $extension = null ) {
    435         if ( ! $extension )
     438        if ( ! $extension ) {
    436439            return false;
     440        }
    437441
    438442        $mime_types = wp_get_mime_types();
     
    441445        foreach ( $extensions as $_extension ) {
    442446            if ( preg_match( "/{$extension}/i", $_extension ) ) {
    443                 return $mime_types[$_extension];
     447                return $mime_types[ $_extension ];
    444448            }
    445449        }
     
    462466        $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) );
    463467
    464         if ( empty( $extensions[0] ) )
     468        if ( empty( $extensions[0] ) ) {
    465469            return false;
     470        }
    466471
    467472        return $extensions[0];
Note: See TracChangeset for help on using the changeset viewer.