QrCodeDataUriGeneratorService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 6 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\QrCode\Contracts\ErrorCorrectionLevelInterface;
15
use Da\QrCode\QrCode;
16
use Da\TwoFA\Contracts\StringGeneratorServiceInterface;
17
18
class QrCodeDataUriGeneratorService implements StringGeneratorServiceInterface
19
{
20
    /**
21
     * @var string a totp secret key uri generated string.
22
     */
23
    private $totpSecretKeyUri;
24
    /**
25
     * @var int the size of the qr code. Recommended size is 200 for readability.
26
     */
27
    private $size;
28
29
    /**
30
     * QrCodeDataUriGeneratorService constructor.
31
     *
32
     * @param string $totpSecreteKeyUri
33
     * @param int    $size
34
     */
35
    public function __construct($totpSecreteKeyUri, $size = 200)
36
    {
37
        $this->totpSecretKeyUri = $totpSecreteKeyUri;
38
        $this->size = $size;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function run()
45
    {
46
        return (new QrCode($this->totpSecretKeyUri, ErrorCorrectionLevelInterface::MEDIUM))
47
            ->setSize((int)$this->size)
48
            ->writeDataUri();
49
    }
50
}
51