Passed
Push — master ( 514bca...891b04 )
by smiley
02:57
created

QRString::text()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 14
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Class QRString
4
 *
5
 * @filesource   QRString.php
6
 * @created      05.12.2015
7
 * @package      chillerlan\QRCode\Output
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2015 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\QRCode\Output;
14
15
use chillerlan\QRCode\QRCode;
16
17
use function implode, is_string, json_encode;
18
19
/**
20
 * Converts the matrix data into string types
21
 */
22
class QRString extends QROutputAbstract{
23
24
	protected string $defaultMode = QRCode::OUTPUT_STRING_TEXT;
25
26
	/**
27
	 * @inheritDoc
28
	 */
29
	protected function setModuleValues():void{
30
31
		foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
32
			$v = $this->options->moduleValues[$M_TYPE] ?? null;
33
34
			if(!is_string($v)){
35
				$this->moduleValues[$M_TYPE] = $defaultValue
36
					? $this->options->textDark
37
					: $this->options->textLight;
38
			}
39
			else{
40
				$this->moduleValues[$M_TYPE] = $v;
41
			}
42
43
		}
44
45
	}
46
47
	/**
48
	 *
49
	 */
50
	protected function text():string{
51
		$str = [];
52
53
		foreach($this->matrix->matrix() as $row){
54
			$r = [];
55
56
			foreach($row as $M_TYPE){
57
				$r[] = $this->moduleValues[$M_TYPE];
58
			}
59
60
			$str[] = implode('', $r);
61
		}
62
63
		return implode($this->options->eol, $str);
64
	}
65
66
	/**
67
	 *
68
	 */
69
	protected function json():string{
70
		return json_encode($this->matrix->matrix());
71
	}
72
73
}
74