MailerDomain   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 15
dl 0
loc 65
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 3 1
A attributeLabels() 0 5 1
A rules() 0 7 1
A isDeleteAllowed() 0 3 2
A find() 0 3 1
A getAccounts() 0 3 1
A getAliases() 0 3 1
1
<?php
2
namespace backend\models;
3
4
use yii\db\ActiveQuery;
5
use yii\db\ActiveRecord;
6
7
/**
8
 * This is the model class for table "mailer_domains".
9
 * @property int $id
10
 * @property string $name
11
 * @property MailerAccount[] $accounts
12
 * @property MailerAlias[] $aliases
13
 */
14
class MailerDomain extends ActiveRecord implements LoggableInterface
15
{
16
    const DOMAIN_PATTERN = '/^(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(?::\d{1,5})?(?:$|[?\/#])/i';
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public static function tableName()
22
    {
23
        return '{{%mailer_domains}}';
24
    }
25
26
    /**
27
     * @return query\MailerDomainQuery
28
     */
29
    public static function find()
30
    {
31
        return new query\MailerDomainQuery(get_called_class());
32
    }
33
34
    /**
35
     * @return ActiveQuery
36
     */
37
    public function getAccounts()
38
    {
39
        return $this->hasMany(MailerAccount::class, ['domain_id' => 'id']);
40
    }
41
42
    /**
43
     * @return ActiveQuery
44
     */
45
    public function getAliases()
46
    {
47
        return $this->hasMany(MailerAlias::class, ['domain_id' => 'id']);
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function rules()
54
    {
55
        return [
56
            [['name'], 'required'],
57
            [['name'], 'string', 'max' => 50],
58
            [['name'], 'match', 'pattern' => self::DOMAIN_PATTERN],
59
            [['name'], 'unique'],
60
        ];
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isDeleteAllowed()
67
    {
68
        return !$this->getAccounts()->count() && !$this->getAliases()->count();
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function attributeLabels()
75
    {
76
        return [
77
            'id' => 'ID',
78
            'name' => 'Domain',
79
        ];
80
    }
81
}
82