Skip to content

Commit cd130af

Browse files
author
Mitch
committed
Uppercase constants and break keywords at same indentation as case body as per PSR, whitespace fix
1 parent b2a160d commit cd130af

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/ImageResize.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
*/
1010
class ImageResize
1111
{
12-
const cropTOP = 1;
13-
const cropCENTRE = 2;
14-
const cropCENTER = 2;
15-
const cropBOTTOM = 3;
16-
const cropLEFT = 4;
17-
const cropRIGHT = 5;
12+
const CROPTOP = 1;
13+
const CROPCENTRE = 2;
14+
const CROPCENTER = 2;
15+
const CROPBOTTOM = 3;
16+
const CROPLEFT = 4;
17+
const CROPRIGHT = 5;
1818

1919
public $quality_jpg = 75;
2020
public $quality_png = 0;
@@ -70,7 +70,7 @@ public static function createFromString($imageData){
7070
* @param string|null $filename
7171
* @throws \Exception
7272
*/
73-
public function __construct($filename=null)
73+
public function __construct($filename = null)
7474
{
7575
if(!empty($filename)) {
7676
$this->load($filename);
@@ -135,18 +135,19 @@ public function load($filename)
135135
switch ($this->source_type) {
136136
case IMAGETYPE_GIF:
137137
$this->source_image = imagecreatefromgif($filename);
138-
break;
138+
break;
139139

140140
case IMAGETYPE_JPEG:
141141
$this->source_image = imagecreatefromjpeg($filename);
142-
break;
142+
break;
143143

144144
case IMAGETYPE_PNG:
145145
$this->source_image = imagecreatefrompng($filename);
146-
break;
146+
break;
147147

148148
default:
149149
throw new \Exception('Unsupported image type');
150+
break;
150151
}
151152

152153
return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
@@ -172,17 +173,17 @@ public function save($filename, $image_type = null, $quality = null, $permission
172173
imagecolortransparent($dest_image, $background);
173174
imagefill($dest_image, 0, 0 , $background);
174175
imagesavealpha($dest_image, true);
175-
break;
176+
break;
176177

177178
case IMAGETYPE_JPEG:
178179
$background = imagecolorallocate($dest_image, 255, 255, 255);
179180
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
180-
break;
181+
break;
181182

182183
case IMAGETYPE_PNG:
183184
imagealphablending($dest_image, false);
184185
imagesavealpha($dest_image, true);
185-
break;
186+
break;
186187
}
187188

188189
imagecopyresampled(
@@ -201,23 +202,23 @@ public function save($filename, $image_type = null, $quality = null, $permission
201202
switch ($image_type) {
202203
case IMAGETYPE_GIF:
203204
imagegif($dest_image, $filename);
204-
break;
205+
break;
205206

206207
case IMAGETYPE_JPEG:
207208
if ($quality === null) {
208209
$quality = $this->quality_jpg;
209210
}
210211

211212
imagejpeg($dest_image, $filename, $quality);
212-
break;
213+
break;
213214

214215
case IMAGETYPE_PNG:
215216
if ($quality === null) {
216217
$quality = $this->quality_png;
217218
}
218219

219220
imagepng($dest_image, $filename, $quality);
220-
break;
221+
break;
221222
}
222223

223224
if ($permissions) {
@@ -351,7 +352,7 @@ public function resize($width, $height, $allow_enlarge = false)
351352
* @param integer $position
352353
* @return \static
353354
*/
354-
public function crop($width, $height, $allow_enlarge = false, $position = self::cropCENTER)
355+
public function crop($width, $height, $allow_enlarge = false, $position = self::CROPCENTER)
355356
{
356357
if (!$allow_enlarge) {
357358
// this logic is slightly different to resize(),
@@ -435,17 +436,18 @@ public function getDestHeight()
435436
* @param integer $position
436437
* @return integer
437438
*/
438-
protected function getCropPosition($expectedSize, $position = self::cropCENTER)
439+
protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
439440
{
440441
$size = 0;
441442
switch ($position) {
442-
case self::cropBOTTOM:
443-
case self::cropRIGHT:
443+
case self::CROPBOTTOM:
444+
case self::CROPRIGHT:
444445
$size = $expectedSize;
445446
break;
446-
case self::cropCENTER:
447-
case self::cropCENTRE:
447+
case self::CROPCENTER:
448+
case self::CROPCENTRE:
448449
$size = $expectedSize / 2;
450+
break;
449451
}
450452
return $size;
451453
}

test/Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testCropPosition() {
149149
$image = $this->createImage(200, 100, 'png');
150150
$resize = new ImageResize($image);
151151

152-
$resize->crop(50, 50, false, $resize::cropRIGHT);
152+
$resize->crop(50, 50, false, $resize::CROPRIGHT);
153153

154154
$reflection_class = new ReflectionClass('\Eventviva\ImageResize');
155155
$source_x = $reflection_class->getProperty('source_x');

0 commit comments

Comments
 (0)