diff --git a/src/Types/TypeITF14.php b/src/Types/TypeITF14.php index 12d6054..d2f87bb 100644 --- a/src/Types/TypeITF14.php +++ b/src/Types/TypeITF14.php @@ -5,6 +5,7 @@ use Picqer\Barcode\Barcode; use Picqer\Barcode\BarcodeBar; use Picqer\Barcode\Exceptions\InvalidCharacterException; +use Picqer\Barcode\Exceptions\InvalidCheckDigitException; use Picqer\Barcode\Exceptions\InvalidLengthException; class TypeITF14 implements TypeInterface @@ -12,6 +13,7 @@ class TypeITF14 implements TypeInterface /** * @throws InvalidLengthException * @throws InvalidCharacterException + * @throws InvalidCheckDigitException */ public function getBarcodeData(string $code): Barcode { @@ -35,6 +37,10 @@ public function getBarcodeData(string $code): Barcode if (strlen($code) === 13) { $code .= $this->getChecksum($code); + } elseif (substr($code, -1) !== $this->getChecksum(substr($code, 0, -1))) { + // If length of given barcode is same as final length, barcode is including checksum + // Make sure that checksum is the same as we calculated + throw new InvalidCheckDigitException(); } $barcode = new Barcode($code);