feat: add stub implementation for image

QRCodeFromEntity

fix: base64 StubQRCodeGenerator
This commit is contained in:
2024-01-17 11:49:52 +01:00
parent 9e96c007bd
commit 64a07b232a
8 changed files with 75 additions and 8 deletions

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
interface QRCodeGeneratorInterface
{
/**
* Generates QR code from entity
* @param QRCode $entity
* @return string base64 encoded PNG
*/
public function generateQRCodeFromEntity(QRCode $entity): string;
}

View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
readonly final class StubQRCodeGenerator implements QRCodeGeneratorInterface
{
public function __construct(private string $imagePath) {}
public function generateQRCodeFromEntity(QRCode $entity): string
{
$content = file_get_contents($this->imagePath);
return match ($content) {
false => throw new \InvalidArgumentException('Image path is invalid'),
default => base64_encode($content)
};
}
}