TwoFactorQrCodeUriGeneratorService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario 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\User\Service;
13
14
use Da\TwoFA\Manager;
15
use Da\TwoFA\Service\QrCodeDataUriGeneratorService;
16
use Da\TwoFA\Service\TOTPSecretKeyUriGeneratorService;
17
use Da\User\Contracts\ServiceInterface;
18
use Da\User\Model\User;
19
use Yii;
20
21
class TwoFactorQrCodeUriGeneratorService implements ServiceInterface
22
{
23
    /**
24
     * @var User
25
     */
26
    protected $user;
27
28
    /**
29
     * TwoFactorQrCodeUriGeneratorService constructor.
30
     *
31
     * @param User $user
32
     */
33
    public function __construct(User $user)
34
    {
35
        $this->user = $user;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function run()
42
    {
43
        $user = $this->user;
44
        if (!$user->auth_tf_key) {
45
            $user->auth_tf_key = (new Manager())->generateSecretKey();
46
            $user->updateAttributes(['auth_tf_key']);
47
        }
48
49
        $totpUri = (new TOTPSecretKeyUriGeneratorService(Yii::$app->name, $user->email, $user->auth_tf_key))->run();
50
51
        return (new QrCodeDataUriGeneratorService($totpUri))->run();
52
    }
53
}
54