Identity::isEmailConfirmed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
use hiam\behaviors\SaveReferralParams;
14
15
/**
16
 * Identity model for MRDP database.
17
 *
18
 * @property string $roles
19
 * @property string $seller
20
 * @property integer $seller_id
21
 */
22
class Identity extends \hiam\models\Identity
23
{
24
    public $roles;
25
    public $seller;
26
    public $seller_id;
27
    public $email_confirmed;
28
    public $email_new;
29
    public $verified;
30
    public $send_me_news;
31
    public $referralParams;
32
33
    protected $activeStates = ['ok', 'active'];
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function rules()
39
    {
40
        return array_merge(parent::rules(), [
41
            ['seller_id',       'integer'],
42
43
            ['seller',          'trim'],
44
            ['seller',          'string', 'min' => 2, 'max' => 64],
45
46
            ['roles',           'trim'],
47
            ['email_confirmed', 'email'],
48
            ['verified',        'boolean'],
49
            ['send_me_news',    'boolean'],
50
        ]);
51
    }
52
53
    public function isActive()
54
    {
55
        return \in_array($this->state, $this->activeStates, true);
56
    }
57
58
    public function isEmailConfirmed()
59
    {
60
        return !empty($this->email_confirmed);
61
    }
62
63
    public function setNewUnconfirmedEmail(string $newEmail): bool
64
    {
65
        $this->email_new = $newEmail;
66
67
        return true;
68
    }
69
70
    public function setConfirmedEmail(string $email)
71
    {
72
        $this->state = 'ok';
73
        $this->email = $email;
74
        $this->email_confirmed = $email;
75
        $this->save();
76
    }
77
}
78