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

AccountConfirmationService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
crap 1
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