Skip to content

Commit 8512460

Browse files
committed
:octocat: extract markup css class generation to QRMarkup::getCssClass()
1 parent 2777a0d commit 8512460

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/Output/QRMarkup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function dump(string $file = null):string{
5454
return $data;
5555
}
5656

57+
/**
58+
* returns a string with all css classes for the current element
59+
*/
60+
abstract protected function getCssClass(int $M_TYPE):string;
61+
5762
/**
5863
*
5964
*/

src/Output/QRMarkupHTML.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class QRMarkupHTML extends QRMarkup{
2323
protected function createMarkup(bool $saveToFile):string{
2424
$html = empty($this->options->cssClass)
2525
? '<div>'
26-
: sprintf('<div class="%s">', $this->options->cssClass);
26+
: sprintf('<div class="%s">', $this->getCssClass());
2727

2828
$html .= $this->options->eol;
2929

@@ -50,4 +50,11 @@ protected function createMarkup(bool $saveToFile):string{
5050
return $html;
5151
}
5252

53+
/**
54+
* @inheritDoc
55+
*/
56+
protected function getCssClass(int $M_TYPE):string{
57+
return $this->options->cssClass;
58+
}
59+
5360
}

src/Output/QRMarkupSVG.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,33 @@ protected function paths():string{
9191
continue;
9292
}
9393

94-
$cssClass = implode(' ', [
95-
'qr-'.$M_TYPE,
96-
($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK ? 'dark' : 'light',
97-
$this->options->cssClass,
98-
]);
99-
10094
$format = empty($this->moduleValues[$M_TYPE])
10195
? '<path class="%1$s" d="%2$s"/>'
10296
: '<path class="%1$s" fill="%3$s" fill-opacity="%4$s" d="%2$s"/>';
10397

104-
$svg[] = sprintf($format, $cssClass, $path, $this->moduleValues[$M_TYPE], $this->options->svgOpacity);
98+
$svg[] = sprintf(
99+
$format,
100+
$this->getCssClass($M_TYPE),
101+
$path,
102+
$this->moduleValues[$M_TYPE],
103+
$this->options->svgOpacity)
104+
;
105105
}
106106

107107
return implode($this->options->eol, $svg);
108108
}
109109

110+
/**
111+
* @inheritDoc
112+
*/
113+
protected function getCssClass(int $M_TYPE):string{
114+
return implode(' ', [
115+
'qr-'.$M_TYPE,
116+
($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK ? 'dark' : 'light',
117+
$this->options->cssClass,
118+
]);
119+
}
120+
110121
/**
111122
* returns a path segment for a single module
112123
*

0 commit comments

Comments
 (0)