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

QRString::dump()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 0
dl 9
loc 9
rs 9.6666
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