QrCodeDataUriGeneratorService::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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(string $totpSecreteKeyUri, int $size = 200)
36
    {
37
        $this->totpSecretKeyUri = $totpSecreteKeyUri;
38
        $this->size = $size;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function run(): string
45
    {
46
        return (new QrCode($this->totpSecretKeyUri, ErrorCorrectionLevelInterface::MEDIUM))
47
            ->setSize((int)$this->size)
48
            ->writeDataUri();
49
    }
50
}
51