Skip to content

Commit

Permalink
Convert helper function, fix namespace, psr2 style
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed May 11, 2019
1 parent 9e90d32 commit 51b5de4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: psr2
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"autoload": {
"psr-4": {
"Jens\\ImageConverter\\": "src/"
}
},
"files": ["src/helper.php"]
},
"autoload-dev": {
"psr-4": {
Expand Down
22 changes: 4 additions & 18 deletions src/ImageConverter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ImageConverter;
namespace Jens\ImageConverter;

class ImageConverter
{
Expand Down Expand Up @@ -86,8 +86,8 @@ private function saveImage($to, $image, $quality)
}


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

switch ($extension) {
Expand All @@ -100,7 +100,7 @@ private function saveImage($to, $image, $quality)
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
}
$image = imagejpeg($image, $to, $quality);
break;
break;
case 'png':
if ($quality < -1 && $quality > 9) {
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
Expand Down Expand Up @@ -169,17 +169,3 @@ private function makeDirectory($to)
return $result;
}
}

/**
* Helper function
*
* @param string $from
* @param string $to
*
* @return resource
* @throws \InvalidArgumentException
*/
function convert($from, $to, $quality = null) {
$converter = new ImageConverter();
return $converter->convert($from, $to, $quality);
}
18 changes: 18 additions & 0 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace ImageConverter;

/**
* Helper function
*
* @param string $from
* @param string $to
*
* @return resource
* @throws \InvalidArgumentException
*/
function convert($from, $to, $quality = null)
{
$converter = new ImageConverter();
return $converter->convert($from, $to, $quality);
}

0 comments on commit 51b5de4

Please sign in to comment.