Test Failed
Push — master ( 1c3827...8aff3a )
by smiley
03:00
created

QRString::text()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 15
rs 9.7666
c 0
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
/**
18
 * Converts the matrix data into string types
19
 */
20
class QRString extends QROutputAbstract{
21
22
	/**
23
	 * @var string
24
	 */
25
	protected $defaultMode = QRCode::OUTPUT_STRING_TEXT;
26
27
	/**
28
	 * @return void
29
	 */
30 View Code Duplication
	protected function setModuleValues():void{
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
32
		foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
33
			$v = $this->options->moduleValues[$M_TYPE] ?? null;
34
35
			if(!is_string($v)){
36
				$this->moduleValues[$M_TYPE] = $defaultValue
37
					? $this->options->textDark
38
					: $this->options->textLight;
39
			}
40
			else{
41
				$this->moduleValues[$M_TYPE] = $v;
42
			}
43
44
		}
45
46
	}
47
48
	/**
49
	 * @return string
50
	 */
51
	protected function text():string{
52
		$str = [];
53
54
		foreach($this->matrix->matrix() as $row){
55
			$r = [];
56
57
			foreach($row as $M_TYPE){
58
				$r[] = $this->moduleValues[$M_TYPE];
59
			}
60
61
			$str[] = implode('', $r);
62
		}
63
64
		return implode($this->options->eol, $str);
65
	}
66
67
	/**
68
	 * @return string
69
	 */
70
	protected function json():string{
71
		return json_encode($this->matrix->matrix());
72
	}
73
74
}
75