| Conditions | 17 |
| Paths | 17 |
| Total Lines | 66 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 106 | public function set_image_size( $string = NULL, $width = NULL, $height = NULL ) { |
||
| 107 | |||
| 108 | |||
| 109 | // If there is no width or height passed |
||
| 110 | if ( empty( $width ) || empty( $height ) ) { |
||
| 111 | |||
| 112 | // And there is no string size passed |
||
| 113 | // And we want to get the image size using PHP |
||
| 114 | if ( empty( $string ) && !empty( $this->getimagesize ) ) { |
||
| 115 | |||
| 116 | $image_size = @getimagesize( $this->src ); |
||
| 117 | |||
| 118 | // If it didn't return a response, it may be a HTTPS/SSL error |
||
| 119 | if ( empty( $image_size[0] ) ) { |
||
| 120 | $image_size = @getimagesize( set_url_scheme( $this->src, 'http' ) ); |
||
| 121 | } |
||
| 122 | |||
| 123 | if ( !empty( $image_size ) ) { |
||
| 124 | list( $width, $height ) = $image_size; |
||
| 125 | } |
||
| 126 | |||
| 127 | } |
||
| 128 | // Otherwise, we calculate based on the string size value |
||
| 129 | else { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @filter `gravityview_image_sizes` Modify the image size presets used by GravityView_Image class |
||
| 133 | * @param array $image_sizes Array of image sizes with the key being the size slug, and the value being an array with `width` and `height` defined, in pixels |
||
| 134 | */ |
||
| 135 | $image_sizes = apply_filters( 'gravityview_image_sizes', array( |
||
| 136 | 'tiny' => array('width' => 40, 'height' => 30), |
||
| 137 | 'small' => array('width' => 100, 'height' => 75), |
||
| 138 | 'medium' => array('width' => 250, 'height' => 188), |
||
| 139 | 'large' => array('width' => 448, 'height' => 336), |
||
| 140 | ) ); |
||
| 141 | |||
| 142 | switch( $this->size ) { |
||
| 143 | case 'tiny': |
||
| 144 | extract($image_sizes['tiny']); |
||
| 145 | break; |
||
| 146 | case 'small': |
||
| 147 | case 's': |
||
| 148 | case 'thumb': |
||
| 149 | extract($image_sizes['small']); |
||
| 150 | break; |
||
| 151 | case 'm': |
||
| 152 | case 'medium': |
||
| 153 | extract($image_sizes['medium']); |
||
| 154 | break; |
||
| 155 | case 'large': |
||
| 156 | case 'l': |
||
| 157 | extract($image_sizes['large']); |
||
| 158 | break; |
||
| 159 | default: |
||
| 160 | // Verify that the passed sizes are integers. |
||
| 161 | $width = !empty( $width ) ? intval( $width ) : intval( $this->width ); |
||
| 162 | $height = !empty( $height ) ? intval( $height ) : intval( $this->height ); |
||
| 163 | } |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | } |
||
| 168 | |||
| 169 | $this->width = $width; |
||
| 170 | $this->height = $height; |
||
| 171 | } |
||
| 172 | |||
| 201 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.