Skip to content

Commit 3f770f6

Browse files
committed
Fix all PHPCS Warnings
1 parent b6e4ef3 commit 3f770f6

3 files changed

Lines changed: 41 additions & 33 deletions

File tree

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ruleset name="PHP_CodeSniffer">
33
<file>.</file>
44
<exclude-pattern>*/vendor/*</exclude-pattern>
5-
<arg value="pn" />
65
<arg name="colors" />
6+
<arg value="p" />
77
<rule ref="PSR2" />
88
</ruleset>

src/Image.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static function resize(\Imagick $source, int $boxWidth, int $boxHeight, a
1717
* resizes images into a bounding box. Maintains aspect ratio, extra space filled with given color.
1818
*
1919
* @param \Imagick $source source image to resize. Will not modify
20-
* @param array $boxSizes resulting bounding boxes. Each value should be an array with width and height, both integers
20+
* @param array $boxSizes resulting bounding boxes. Each value should be an array with width and height, both
21+
* integers
2122
* @param array $options options
2223
* string color (default white) background color. Any supported from
2324
* http://www.imagemagick.org/script/color.php#color_names
@@ -39,10 +40,10 @@ public static function resize(\Imagick $source, int $boxWidth, int $boxHeight, a
3940
*/
4041
public static function resizeMulti(\Imagick $source, array $boxSizes, array $options = []) : array
4142
{
42-
//algorithm inspiration from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
43-
//use of 2x2 binning is arguably the best quality one will get downsizing and is what lots of hardware does in the photography field,
44-
//while being reasonably fast. Upsizing is more subjective but you can't get much better than bicubic which is what is used here.
45-
43+
//algorithm inspired from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
44+
//use of 2x2 binning is arguably the best quality one will get downsizing and is what lots of hardware does in
45+
//the photography field, while being reasonably fast. Upsizing is more subjective but you can't get much
46+
//better than bicubic which is what is used here.
4647
$color = 'white';
4748
if (isset($options['color'])) {
4849
$color = $options['color'];
@@ -122,7 +123,8 @@ public static function resizeMulti(\Imagick $source, array $boxSizes, array $opt
122123

123124
//ratio over 1 is horizontal, under 1 is vertical
124125
$boxRatio = $boxWidth / $boxHeight;
125-
$originalRatio = $width / $height;//height should be positive since I didnt find a way you could get zero into imagick
126+
//height should be positive since I didnt find a way you could get zero into imagick
127+
$originalRatio = $width / $height;
126128

127129
$targetWidth = null;
128130
$targetHeight = null;
@@ -148,7 +150,8 @@ public static function resizeMulti(\Imagick $source, array $boxSizes, array $opt
148150
}
149151
}
150152

151-
//do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target width and height
153+
//do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target
154+
//width and height
152155
while (true) {
153156
$widthReduced = false;
154157
$widthIsHalf = false;
@@ -213,8 +216,8 @@ public static function resizeMulti(\Imagick $source, array $boxSizes, array $opt
213216
throw new \Exception('Imagick::compositeImage() did not return true');//@codeCoverageIgnore
214217
}
215218

216-
//reason we are not supporting the options in self::write() here is because format, and strip headers are only relevant once written
217-
//Imagick::stripImage() doesnt even have an effect until written
219+
//reason we are not supporting the options in self::write() here is because format, and strip headers are
220+
//only relevant once written Imagick::stripImage() doesnt even have an effect until written
218221
//also the user can just call that function with the resultant $canvas
219222
$results[$boxSizeKey] = $canvas;
220223
}
@@ -228,10 +231,11 @@ public static function resizeMulti(\Imagick $source, array $boxSizes, array $opt
228231
* @param \Imagick $source source image. Will not modify
229232
* @param string $destPath destination image path
230233
* @param array $options options
231-
* string format (default jpeg) format. Any supported from http://www.imagemagick.org/script/formats.php#supported
232-
* int directoryMode (default 0777) chmod mode for any parent directories created
233-
* int fileMode (default 0777) chmod mode for the resized image file
234-
* bool stripHeaders (default true) whether to strip headers (exif, etc). Is only reflected in $destPath, not returned clone
234+
* string format (default jpeg) Any from http://www.imagemagick.org/script/formats.php#supported
235+
* int directoryMode (default 0777) chmod mode for any parent directories created
236+
* int fileMode (default 0777) chmod mode for the resized image file
237+
* bool stripHeaders (default true) whether to strip headers (exif, etc). Is only reflected in $destPath,
238+
* not returned clone
235239
*
236240
* @return void
237241
*

tests/ImageTest.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
*/
1010
final class ImageTest extends TestCase
1111
{
12-
private $_sourceFilesDir;
13-
private $_tempDir;
12+
private $sourceFilesDir;
13+
private $tempDir;
1414

1515
public function setUp()
1616
{
17-
$this->_sourceFilesDir = __DIR__ . '/_files';
18-
$this->_tempDir = sys_get_temp_dir() . '/imageUtilTest';
19-
if (is_dir($this->_tempDir)) {
20-
foreach (glob("{$this->_tempDir}/*") as $file) {
17+
$this->sourceFilesDir = __DIR__ . '/_files';
18+
$this->tempDir = sys_get_temp_dir() . '/imageUtilTest';
19+
if (is_dir($this->tempDir)) {
20+
foreach (glob("{$this->tempDir}/*") as $file) {
2121
unlink($file);
2222
}
2323

24-
rmdir($this->_tempDir);
24+
rmdir($this->tempDir);
2525
}
2626
}
2727

@@ -320,10 +320,10 @@ public function resizeNonBoolUpsize()
320320
public function resizeOrientation()
321321
{
322322
$files = [
323-
"{$this->_sourceFilesDir}/bottom-right.jpg",
324-
"{$this->_sourceFilesDir}/left-bottom.jpg",
325-
"{$this->_sourceFilesDir}/right-top.jpg",
326-
"{$this->_sourceFilesDir}/top-left.jpg",
323+
"{$this->sourceFilesDir}/bottom-right.jpg",
324+
"{$this->sourceFilesDir}/left-bottom.jpg",
325+
"{$this->sourceFilesDir}/right-top.jpg",
326+
"{$this->sourceFilesDir}/top-left.jpg",
327327
];
328328

329329
$imageResults = [];
@@ -476,19 +476,23 @@ public function resizeMultiNonIntHeight()
476476
*/
477477
public function write()
478478
{
479-
$destPath = "{$this->_tempDir}/dest.jpeg";
479+
$destPath = "{$this->tempDir}/dest.jpeg";
480480

481-
$source = new \Imagick("{$this->_sourceFilesDir}/exif.jpg");
481+
$source = new \Imagick("{$this->sourceFilesDir}/exif.jpg");
482482
$source->setImageFormat('png');
483483

484-
Image::write($source, $destPath, ['format' => 'jpeg', 'directoryMode' => 0775, 'fileMode' => 0776, 'stripHeaders' => true]);
484+
Image::write(
485+
$source,
486+
$destPath,
487+
['format' => 'jpeg', 'directoryMode' => 0775, 'fileMode' => 0776, 'stripHeaders' => true]
488+
);
485489

486490
$destImage = new \Imagick($destPath);
487491

488492
$this->assertSame(0, count($destImage->getImageProperties('exif:*')));
489493
$this->assertSame('JPEG', $destImage->getImageFormat());
490494

491-
$directoryPermissions = substr(sprintf('%o', fileperms($this->_tempDir)), -4);
495+
$directoryPermissions = substr(sprintf('%o', fileperms($this->tempDir)), -4);
492496
$filePermissions = substr(sprintf('%o', fileperms($destPath)), -4);
493497

494498
$this->assertSame('0775', $directoryPermissions);
@@ -547,10 +551,10 @@ public function writeNonBoolStripHeaders()
547551
*/
548552
public function stripHeaders()
549553
{
550-
$path = "{$this->_tempDir}/stripHeaders.jpg";
554+
$path = "{$this->tempDir}/stripHeaders.jpg";
551555

552-
mkdir($this->_tempDir);
553-
copy("{$this->_sourceFilesDir}/exif.jpg", $path);
556+
mkdir($this->tempDir);
557+
copy("{$this->sourceFilesDir}/exif.jpg", $path);
554558

555559
Image::stripHeaders($path);
556560

@@ -567,6 +571,6 @@ public function stripHeaders()
567571
*/
568572
public function stripHeadersMissingImage()
569573
{
570-
Image::stripHeaders("{$this->_tempDir}/doesnotexist.jpg");
574+
Image::stripHeaders("{$this->tempDir}/doesnotexist.jpg");
571575
}
572576
}

0 commit comments

Comments
 (0)