Total Complexity | 7 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 94.74% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class QrCodeImageForPdf |
||
9 | { |
||
10 | protected string $tmpFileName = ''; |
||
11 | |||
12 | 1 | public function __construct(string $content, array $options = []) |
|
13 | { |
||
14 | 1 | $this->tmpFileName = $this->generateTemporalFileName('png'); |
|
15 | 1 | ( new QRCode($content, $options) )->writePngFile($this->tmpFileName); |
|
16 | 1 | static::convertImageTo8bit($this->tmpFileName); |
|
17 | } |
||
18 | |||
19 | 1 | public static function make(...$arguments): static |
|
20 | { |
||
21 | 1 | return new static(...$arguments); |
|
|
|||
22 | } |
||
23 | |||
24 | 1 | public function filePath(): string |
|
25 | { |
||
26 | 1 | return $this->tmpFileName; |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * Create temporal file name. |
||
31 | * |
||
32 | * @param string|null $ext |
||
33 | * |
||
34 | * @return string |
||
35 | * @throws \Exception |
||
36 | */ |
||
37 | 1 | protected function generateTemporalFileName(?string $ext = null): string |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * FPDF support only 8 bit colors - so we need convert image before insert |
||
52 | * @param string $path |
||
53 | */ |
||
54 | 1 | public static function convertImageTo8bit(string $path): void |
|
61 |