Completed
Push — master ( ef42ef...514bca )
by smiley
06:10
created

QRString   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 30.91 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 17
loc 55
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use function implode, is_string, json_encode;
18
19
/**
20
 * Converts the matrix data into string types
21
 */
22
class QRString extends QROutputAbstract{
23
24
	protected string $defaultMode = QRCode::OUTPUT_STRING_TEXT;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

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