Completed
Push — master ( cd3826...eb0f06 )
by smiley
03:16
created

QRString::dump()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 11
rs 9.4285
c 1
b 0
f 1
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
	/**
23
	 * @return string
24
	 */
25
	public function dump():string{
26
27
		switch($this->options->outputType){
28
			case QRCode::OUTPUT_STRING_TEXT:
29
				return $this->toString();
30
			case QRCode::OUTPUT_STRING_JSON:
31
			default:
32
				return json_encode($this->matrix->matrix());
33
		}
34
35
	}
36
37
	/**
38
	 * @return string
39
	 */
40
	protected function toString():string{
41
		$str = '';
42
43
		foreach($this->matrix->matrix() as $row){
44
			foreach($row as $col){
45
				$col = $this->options->moduleValues[$col];
46
				
47
				// fallback
48
				if(is_bool($col) || !is_string($col)){
49
					$col = $col ? $this->options->textDark : $this->options->textLight;
50
				}
51
52
53
				$str .= $col;
54
			}
55
56
			$str .= $this->options->eol;
57
		}
58
59
		return $str;
60
	}
61
62
}
63