Passed
Push — main ( c8c37a...b37fa3 )
by smiley
02:07
created

QRMarkupHTML::getCssClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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->getCssClass(0)); // @todo $M_TYPE
27
28
		$html .= $this->options->eol;
29
30
		for($y = 0; $y < $this->moduleCount; $y++){
31
			$html .= '<div>';
32
33
			for($x = 0; $x < $this->moduleCount; $x++){
34
				$html .= sprintf('<span style="background: %s;"></span>', $this->getModuleValueAt($x, $y));
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><html lang=""><head><meta charset="UTF-8"><title>QR Code</title></head><body>%s</body></html>',
46
				$this->options->eol.$html
47
			);
48
		}
49
50
		return $html;
51
	}
52
53
}
54