Skip to content

Commit 51b5de4

Browse files
committed
Convert helper function, fix namespace, psr2 style
1 parent 9e90d32 commit 51b5de4

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"autoload": {
1818
"psr-4": {
1919
"Jens\\ImageConverter\\": "src/"
20-
}
20+
},
21+
"files": ["src/helper.php"]
2122
},
2223
"autoload-dev": {
2324
"psr-4": {

src/ImageConverter.php

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ImageConverter;
3+
namespace Jens\ImageConverter;
44

55
class ImageConverter
66
{
@@ -86,8 +86,8 @@ private function saveImage($to, $image, $quality)
8686
}
8787

8888

89-
if(isset($quality) && !is_int($quality)) {
90-
throw new \InvalidArgumentException(sprintf('The %s quality has to be an integer', $quality));
89+
if (isset($quality) && !is_int($quality)) {
90+
throw new \InvalidArgumentException(sprintf('The %s quality has to be an integer', $quality));
9191
}
9292

9393
switch ($extension) {
@@ -100,7 +100,7 @@ private function saveImage($to, $image, $quality)
100100
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
101101
}
102102
$image = imagejpeg($image, $to, $quality);
103-
break;
103+
break;
104104
case 'png':
105105
if ($quality < -1 && $quality > 9) {
106106
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
@@ -169,17 +169,3 @@ private function makeDirectory($to)
169169
return $result;
170170
}
171171
}
172-
173-
/**
174-
* Helper function
175-
*
176-
* @param string $from
177-
* @param string $to
178-
*
179-
* @return resource
180-
* @throws \InvalidArgumentException
181-
*/
182-
function convert($from, $to, $quality = null) {
183-
$converter = new ImageConverter();
184-
return $converter->convert($from, $to, $quality);
185-
}

src/helper.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace ImageConverter;
4+
5+
/**
6+
* Helper function
7+
*
8+
* @param string $from
9+
* @param string $to
10+
*
11+
* @return resource
12+
* @throws \InvalidArgumentException
13+
*/
14+
function convert($from, $to, $quality = null)
15+
{
16+
$converter = new ImageConverter();
17+
return $converter->convert($from, $to, $quality);
18+
}

0 commit comments

Comments
 (0)