GoogleQrCodeUrlGeneratorService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 4 1
A getQueryParameters() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/2fa-library project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\TwoFA\Service;
13
14
use Da\TwoFA\Contracts\StringGeneratorServiceInterface;
15
16
final class GoogleQrCodeUrlGeneratorService implements StringGeneratorServiceInterface
17
{
18
    /**
19
     * @var string a totp secret key uri generated string.
20
     */
21
    private $totpSecretKeyUri;
22
    /**
23
     * @var int the size of the qr code. Recommended size is 200 for readability.
24
     */
25
    private $size;
26
27
    /**
28
     * GoogleQrCodeUrlService constructor.
29
     *
30
     * @param string $totpSecreteKeyUri
31
     * @param int    $size
32
     */
33
    public function __construct($totpSecreteKeyUri, $size = 200)
34
    {
35
        $this->totpSecretKeyUri = $totpSecreteKeyUri;
36
        $this->size = $size;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function run()
43
    {
44
        return sprintf('https://chart.googleapis.com/%s?%s', rawurlencode('chart'), $this->getQueryParameters());
45
    }
46
47
    /**
48
     * @return string the constructed query parameters for google charts.
49
     */
50
    protected function getQueryParameters()
51
    {
52
        return sprintf(
53
            'chs=%sx%s&chld=M|0&cht=qr&chl=%s',
54
            $this->size,
55
            $this->size,
56
            urlencode($this->totpSecretKeyUri)
57
        );
58
    }
59
}
60