Files
michaelschiemer/src/Domain/QrCode/QrCode.php

48 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Domain\QrCode;
use App\Domain\QrCode\Exception\QrCodeException;
use App\Domain\QrCode\ValueObject\ErrorCorrectionLevel;
use App\Domain\QrCode\ValueObject\QrCodeVersion;
readonly class QrCode
{
public function __construct(
private string $data,
private ErrorCorrectionLevel $errorCorrectionLevel = ErrorCorrectionLevel::M,
private ?QrCodeVersion $version = null
) {
if (empty($data)) {
throw new QrCodeException('QR Code Daten dürfen nicht leer sein');
}
}
public function getData(): string
{
return $this->data;
}
public function getErrorCorrectionLevel(): ErrorCorrectionLevel
{
return $this->errorCorrectionLevel;
}
public function getVersion(): ?QrCodeVersion
{
return $this->version;
}
public function withErrorCorrectionLevel(ErrorCorrectionLevel $level): self
{
return new self($this->data, $level, $this->version);
}
public function withVersion(QrCodeVersion $version): self
{
return new self($this->data, $this->errorCorrectionLevel, $version);
}
}