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

UserConfirmationService::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0078
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