validator->validate($code)) !== 0) { throw new \InvalidArgumentException("QRCode entity is not valid"); } return new QRCode( $code->getIban() ?? throw new ThisShouldNeverHappenException("iban not set"), \DateTimeImmutable::createFromMutable($code->getDueDate() ?? throw new ThisShouldNeverHappenException("due date not set")), $code->getMessage() ?? throw new ThisShouldNeverHappenException("message not set"), $this->convertMoney($code->getMoney() ?? throw new ThisShouldNeverHappenException("money not set")), $this->convertCodeOptions($code->getCodeQROptions() ?? throw new ThisShouldNeverHappenException("codeQROptions not set")), $this->convertIdentification($code->getPaymentIdentification()) ); } protected function convertMoney(\App\Entity\Input\QRCode\QRCodeMoney $money): QRCodeMoney { return new QRCodeMoney( $money->getAmount() ?? throw new ThisShouldNeverHappenException("amount not set"), $money->getCurrency() ?? throw new ThisShouldNeverHappenException("currency not set") ); } protected function convertCodeOptions(\App\Entity\Input\QRCode\QRCodeQROptions $options): QRCodeQROptions { return new QRCodeQROptions( $options->getScale(), $options->getMargin() ); } protected function convertIdentification(?\App\Entity\Input\QRCode\QRCodePaymentIdentification $ident): ?QRCodePaymentIdentification { return match ($ident) { null => null, default => new QRCodePaymentIdentification( $ident->getVariableSymbol(), $ident->getSpecificSymbol(), $ident->getConstantSymbol() ) }; } }