Passed
Push — main ( da7af7...cde2af )
by smiley
02:10
created

QRMarkupHTML   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A createMarkup() 0 28 5
1
<?php
2
/**
3
 * Class QRMarkupHTML
4
 *
5
 * @created      06.06.2022
6
 * @author       smiley <[email protected]>
7
 * @copyright    2022 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\QRCode\Output;
12
13
use function sprintf;
14
15
/**
16
 * HTML output
17
 */
18
class QRMarkupHTML extends QRMarkup{
19
20
	/**
21
	 * @inheritDoc
22
	 */
23
	protected function createMarkup(bool $saveToFile):string{
24
		$html = empty($this->options->cssClass)
25
			? '<div>'
26
			: sprintf('<div class="%s">', $this->options->cssClass);
27
28
		$html .= $this->options->eol;
29
30
		foreach($this->matrix->matrix() as $row){
31
			$html .= '<div>';
32
33
			foreach($row as $M_TYPE){
34
				$html .= sprintf('<span style="background: %s;"></span>', $this->moduleValues[$M_TYPE]);
35
			}
36
37
			$html .= '</div>'.$this->options->eol;
38
		}
39
40
		$html .= '</div>'.$this->options->eol;
41
42
		// wrap the snippet into a body when saving to file
43
		if($saveToFile){
44
			$html = sprintf(
45
				'<!DOCTYPE html><head><meta charset="UTF-8"><title>QR Code</title></head><body>%s</body>',
46
				$this->options->eol.$html
47
			);
48
		}
49
50
		return $html;
51
	}
52
53
}
54