File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55use Picqer \Barcode \Barcode ;
66use Picqer \Barcode \BarcodeBar ;
77use Picqer \Barcode \Exceptions \InvalidCharacterException ;
8+ use Picqer \Barcode \Exceptions \InvalidCheckDigitException ;
89use Picqer \Barcode \Exceptions \InvalidLengthException ;
910
1011class TypeITF14 implements TypeInterface
1112{
1213 /**
1314 * @throws InvalidLengthException
1415 * @throws InvalidCharacterException
16+ * @throws InvalidCheckDigitException
1517 */
1618 public function getBarcodeData (string $ code ): Barcode
1719 {
@@ -35,6 +37,10 @@ public function getBarcodeData(string $code): Barcode
3537
3638 if (strlen ($ code ) === 13 ) {
3739 $ code .= $ this ->getChecksum ($ code );
40+ } elseif (substr ($ code , -1 ) !== $ this ->getChecksum (substr ($ code , 0 , -1 ))) {
41+ // If length of given barcode is same as final length, barcode is including checksum
42+ // Make sure that checksum is the same as we calculated
43+ throw new InvalidCheckDigitException ();
3844 }
3945
4046 $ barcode = new Barcode ($ code );
You can’t perform that action at this time.
0 commit comments