Passed
Branch master (947605)
by smiley
03:06
created

MyCustomOutput   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 5
loc 20
rs 10

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
require_once '../vendor/autoload.php';
4
5
use chillerlan\QRCode\QRCode;
6
use chillerlan\QRCode\QROptions;
7
use chillerlan\QRCode\Output\QROutputBase;
8
use chillerlan\QRCode\Output\QROutputInterface;
9
10
11
/**
12
 * Class MyCustomOutput
13
 */
14
class MyCustomOutput extends QROutputBase implements QROutputInterface{
15
16
	/**
17
	 * @return mixed
18
	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
19
	 */
20
	public function dump(){
21
22
		$output = '';
23
24
		for($row = 0; $row < $this->pixelCount; $row++){
25
			for($col = 0; $col < $this->pixelCount; $col++){
26
				$output .= (string)(int)$this->matrix[$row][$col];
27
			}
28
		}
29
30
		return $output;
31
	}
32
33
}
34
35
$starttime = microtime(true);
36
37
echo (new QRCode('otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', new MyCustomOutput))->output();
38
39
echo PHP_EOL.'QRCode: '.round((microtime(true)-$starttime), 5);
40