Passed
Push — master ( eb0f06...7df5a4 )
by smiley
03:39
created

QRAuthenticator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getURIQRCode() 0 5 1
A getAuthenticator() 0 8 1
1
<?php
2
/**
3
 * Trait QRAuthenticator
4
 *
5
 * @filesource   QRAuthenticator.php
6
 * @created      21.12.2017
7
 * @package      chillerlan\QRCode\Traits
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\QRCode\Traits;
14
15
use chillerlan\Authenticator\Authenticator;
16
use chillerlan\QRCode\QRCode;
17
18
/**
19
 * Creates URI QR Codes for use with mmobile authenticators
20
 */
21
trait QRAuthenticator{
22
23
	/**
24
	 * @var \chillerlan\QRCode\QROptions
25
	 */
26
	protected $qrOptions;
27
28
	/**
29
	 * @var string
30
	 */
31
	protected $authenticatorSecret;
32
33
	/**
34
	 * @var int
35
	 */
36
	protected $authenticatorDigits = Authenticator::DEFAULT_DIGITS;
37
38
	/**
39
	 * @var int
40
	 */
41
	protected $authenticatorPeriod = Authenticator::DEFAULT_PERIOD;
42
43
	/**
44
	 * @var string
45
	 */
46
	protected $authenticatorMode   = Authenticator::DEFAULT_AUTH_MODE;
47
48
	/**
49
	 * @var string
50
	 */
51
	protected $authenticatorAlgo   = Authenticator::DEFAULT_HASH_ALGO;
52
53
	/**
54
	 * @param string $label
55
	 * @param string $issuer
56
	 *
57
	 * @return mixed
58
	 */
59
	protected function getURIQRCode(string $label, string $issuer) {
60
		$uri = $this->getAuthenticator()->setSecret($this->authenticatorSecret)->getUri($label, $issuer);
61
62
		return (new QRCode($this->qrOptions))->render($uri);
63
	}
64
65
	/**
66
	 * @return \chillerlan\Authenticator\Authenticator
67
	 */
68
	protected function getAuthenticator():Authenticator {
69
		return (new Authenticator)
70
			->setPeriod($this->authenticatorPeriod)
71
			->setDigits($this->authenticatorDigits)
72
			->setMode($this->authenticatorMode)
73
			->setAlgorithm($this->authenticatorAlgo)
74
		;
75
	}
76
77
}
78