Skip to content

Commit f754cbd

Browse files
authored
Merge pull request picqer#49 from OskarStark/exception
throw exception instead of returning false
2 parents 7d90abc + 6bccdc4 commit f754cbd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/BarcodeGeneratorJPG.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\BarcodeException;
6+
57
class BarcodeGeneratorJPG extends BarcodeGenerator
68
{
79

@@ -15,6 +17,7 @@ class BarcodeGeneratorJPG extends BarcodeGenerator
1517
* @param array $color RGB (0-255) foreground color for bar elements (background is transparent).
1618
* @return string image data or false in case of error.
1719
* @public
20+
* @throws BarcodeException
1821
*/
1922
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0))
2023
{
@@ -39,7 +42,7 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c
3942
$imageMagickObject = new \imagickdraw();
4043
$imageMagickObject->setFillColor($colorForeground);
4144
} else {
42-
return false;
45+
throw new BarcodeException('Neither gd-lib or imagick are installed!');
4346
}
4447

4548
// print bars

src/BarcodeGeneratorPNG.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Picqer\Barcode;
44

5+
use Picqer\Barcode\Exceptions\BarcodeException;
6+
57
class BarcodeGeneratorPNG extends BarcodeGenerator
68
{
79

@@ -39,7 +41,7 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c
3941
$imageMagickObject = new \imagickdraw();
4042
$imageMagickObject->setFillColor($colorForeground);
4143
} else {
42-
return false;
44+
throw new BarcodeException('Neither gd-lib or imagick are installed!');
4345
}
4446

4547
// print bars

0 commit comments

Comments
 (0)