Completed
Pull Request — master (#251)
by
unknown
02:45
created

UserConfirmationService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 14 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\User\Contracts\ServiceInterface;
15
use Da\User\Event\UserEvent;
16
use Da\User\Model\User;
17
use Da\User\Traits\MailAwareTrait;
18
19
class UserConfirmationService implements ServiceInterface
20
{
21
    use MailAwareTrait;
22
    
23
    protected $model;
24
25 1
    public function __construct(User $model)
26
    {
27 1
        $this->model = $model;
28 1
    }
29
30 1
    public function run()
31
    {
32 1
        $model = $this->model;
33 1
        $event = $this->make(UserEvent::class, [$model]);
34
        
35 1
        $this->model->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION, $event);
36 1
        if ((bool)$this->model->updateAttributes(['confirmed_at' => time()])) {
37 1
            $this->model->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event);
38
39 1
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45