Completed
Push — master ( 443bff...94d0aa )
by Dmitry
13:27
created

Identity::setConfirmedEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * HIAM module for MRDP database compatibility
4
 *
5
 * @link      https://github.com/hiqdev/hiam-mrdp
6
 * @package   hiam-mrdp
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiam\mrdp\models;
12
13
/**
14
 * Identity model for MRDP database.
15
 *
16
 * @property string $roles
17
 * @property string $seller
18
 * @property integer $seller_id
19
 */
20
class Identity extends \hiam\models\Identity
21
{
22
    public $roles;
23
    public $seller;
24
    public $seller_id;
25
    public $email_confirmed;
26
    public $email_new;
27
    public $send_me_news;
28
29
    protected $activeStates = ['ok', 'active'];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function rules()
35
    {
36
        return array_merge(parent::rules(), [
37
            ['seller_id',       'integer'],
38
39
            ['seller',          'trim'],
40
            ['seller',          'string', 'min' => 2, 'max' => 64],
41
42
            ['roles',           'trim'],
43
            ['email_confirmed', 'email'],
44
            ['send_me_news',    'boolean'],
45
        ]);
46
    }
47
48
    public function isActive()
49
    {
50
        return \in_array($this->state, $this->activeStates, true);
51
    }
52
53
    public function isEmailConfirmed()
54
    {
55
        return !empty($this->email_confirmed);
56
    }
57
58
    public function setNewUnconfirmedEmail(string $newEmail): bool
59
    {
60
        $this->email_new = $newEmail;
61
62
        return true;
63
    }
64
65
    public function setConfirmedEmail(string $email)
66
    {
67
        $this->state = 'ok';
68
        $this->email = $email;
69
        $this->email_confirmed = $email;
70
        $this->save();
71
    }
72
}
73