Completed
Push — master ( 645168...459db1 )
by smiley
03:19
created

QRString::toString()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
c 0
b 0
f 0
nc 5
nop 0
dl 0
loc 24
rs 8.5125

1 Method

Rating   Name   Duplication   Size   Complexity  
A QRString::json() 0 3 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 View Code Duplication
	public function dump():string{
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...
26
		$data = call_user_func([$this, $this->outputMode ?? QRCode::OUTPUT_STRING_TEXT]);
27
28
		if($this->options->cachefile !== null){
29
			$this->saveToFile($data);
30
		}
31
32
		return $data;
33
	}
34
35
	/**
36
	 * @return string
37
	 */
38
	protected function text():string{
39
		$str = [];
40
41
		foreach($this->matrix->matrix() as $row){
42
			$r = [];
43
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
50
						? $this->options->textDark
51
						: $this->options->textLight;
52
				}
53
54
				$r[] = $col;
55
			}
56
57
			$str[] = implode('', $r);
58
		}
59
60
		return implode($this->options->eol, $str);
61
	}
62
63
	protected function json(){
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
64
		return json_encode($this->matrix->matrix());
65
	}
66
67
}
68