diff --git a/src/Types/TypePharmacodeTwoCode.php b/src/Types/TypePharmacodeTwoCode.php index dca3811..7c1959a 100644 --- a/src/Types/TypePharmacodeTwoCode.php +++ b/src/Types/TypePharmacodeTwoCode.php @@ -9,6 +9,7 @@ use Picqer\Barcode\Barcode; use Picqer\Barcode\BarcodeBar; +use Picqer\Barcode\Exceptions\InvalidLengthException; class TypePharmacodeTwoCode implements TypeInterface { @@ -16,6 +17,10 @@ public function getBarcodeData(string $code): Barcode { $code = intval($code); + if ($code < 1) { + throw new InvalidLengthException('Pharmacode 2 needs a number of 1 or larger'); + } + $seq = ''; do { diff --git a/tests/PharmacodeTest.php b/tests/PharmacodeTest.php new file mode 100644 index 0000000..c068ffb --- /dev/null +++ b/tests/PharmacodeTest.php @@ -0,0 +1,15 @@ +expectException(Picqer\Barcode\Exceptions\InvalidLengthException::class); + + $pharmacode->getBarcodeData('0'); + } +}