Completed
Push — master ( 5ee4c9...308b6a )
by Antonio
05:05
created

AccountConfirmationService::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.072

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 8
cts 10
cp 0.8
rs 9.4285
cc 3
eloc 10
nc 2
nop 0
crap 3.072
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\User\Contracts\ServiceInterface;
15
use Da\User\Model\Token;
16
use Da\User\Model\User;
17
use Da\User\Query\TokenQuery;
18
19
class AccountConfirmationService implements ServiceInterface
20
{
21
    protected $model;
22
    protected $code;
23
    protected $tokenQuery;
24
    protected $userConfirmationService;
25
26 1
    public function __construct(
27
        $code,
28
        User $model,
29
        UserConfirmationService $userConfirmationService,
30
        TokenQuery $tokenQuery
31
    ) {
32 1
        $this->code = $code;
33 1
        $this->model = $model;
34 1
        $this->userConfirmationService = $userConfirmationService;
35 1
        $this->tokenQuery = $tokenQuery;
36 1
    }
37
38 1
    public function run()
39
    {
40 1
        $token = $this->tokenQuery
41 1
            ->whereUserId($this->model->id)
42 1
            ->whereCode($this->code)
43 1
            ->whereIsConfirmationType()
44 1
            ->one();
45
46 1
        if ($token instanceof Token && !$token->getIsExpired()) {
47
            $token->delete();
48
49
            return $this->userConfirmationService->run();
50
        }
51
52 1
        return false;
53
    }
54
}
55