Passed
Push — master ( 459db1...1dc4c7 )
by smiley
02:05
created

QRString::text()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
c 0
b 0
f 0
nc 5
nop 0
dl 0
loc 24
rs 8.5125
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
/**
18
 * Converts the matrix data into string types
19
 */
20
class QRString extends QROutputAbstract{
21
22
	protected $defaultMode = QRCode::OUTPUT_STRING_TEXT;
23
24
	/**
25
	 * @return string
26
	 */
27
	protected function text():string{
28
		$str = [];
29
30
		foreach($this->matrix->matrix() as $row){
31
			$r = [];
32
33
			foreach($row as $col){
34
				$col = $this->options->moduleValues[$col];
35
36
				// fallback
37
				if(is_bool($col) || !is_string($col)){
38
					$col = $col
39
						? $this->options->textDark
40
						: $this->options->textLight;
41
				}
42
43
				$r[] = $col;
44
			}
45
46
			$str[] = implode('', $r);
47
		}
48
49
		return implode($this->options->eol, $str);
50
	}
51
52
	/**
53
	 * @return string
54
	 */
55
	protected function json():string{
56
		return json_encode($this->matrix->matrix());
57
	}
58
59
}
60