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

QRString   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 43
rs 10
wmc 9
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dump() 0 11 3
B toString() 0 21 6
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