Completed
Push — master ( 831b77...b56796 )
by Antonio
02:41
created

UserConfirmationService::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2.0185
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
18
class UserConfirmationService implements ServiceInterface
19
{
20
    protected $model;
21
22 1
    public function __construct(User $model)
23
    {
24 1
        $this->model = $model;
25 1
    }
26
27 1
    public function run()
28
    {
29 1
        $this->model->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION);
30 1
        if ((bool)$this->model->updateAttributes(['confirmed_at' => time()])) {
31 1
            $this->model->trigger(UserEvent::EVENT_AFTER_CONFIRMATION);
32
33 1
            return true;
34
        }
35
36
        return false;
37
    }
38
}
39