. */ declare(strict_types=1); namespace App\Services\LabelSystem\BarcodeScanner; use GtinValidation\GtinValidator; readonly class GTINBarcodeScanResult implements BarcodeScanResultInterface { private GtinValidator $validator; public function __construct( public string $gtin, ) { $this->validator = new GtinValidator($this->gtin); } public function getDecodedForInfoMode(): array { $obj = $this->validator->getGtinObject(); return [ 'GTIN' => $this->gtin, 'GTIN type' => $obj->getType(), 'Valid' => $this->validator->isValid() ? 'Yes' : 'No', ]; } /** * Checks if the given input is a valid GTIN. This is used to determine whether a scanned barcode should be interpreted as a GTIN or not. * @param string $input * @return bool */ public static function isValidGTIN(string $input): bool { try { return (new GtinValidator($input))->isValid(); } catch (\Exception $e) { return false; } } }