MailerAlias   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A attributeLabels() 0 7 1
A rules() 0 8 1
A __toString() 0 3 1
A tableName() 0 3 1
A getDomain() 0 3 1
1
<?php
2
namespace backend\models;
3
4
use yii\db\ActiveRecord;
5
use yii\db\ActiveQuery;
6
7
/**
8
 * This is the model class for table "mailer_aliases".
9
 * @property int $id
10
 * @property int $domain_id
11
 * @property string $source
12
 * @property string $destination
13
 * @property MailerDomain $domain
14
 */
15
class MailerAlias extends ActiveRecord implements LoggableInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public static function tableName()
21
    {
22
        return '{{%mailer_aliases}}';
23
    }
24
25
    /**
26
     * @return ActiveQuery
27
     */
28
    public function getDomain()
29
    {
30
        return $this->hasOne(MailerDomain::class, ['id' => 'domain_id']);
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function rules()
37
    {
38
        return [
39
            [['domain_id', 'source', 'destination'], 'required'],
40
            [['domain_id'], 'exist', 'targetClass' => MailerDomain::class, 'targetAttribute' => 'id'],
41
            [['source', 'destination'], 'string', 'max' => 100],
42
            [['domain_id', 'source', 'destination'], 'unique',
43
                'targetAttribute' => ['domain_id', 'source', 'destination'], 'message' => 'Alias is not unique'],
44
        ];
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function attributeLabels()
51
    {
52
        return [
53
            'id' => 'ID',
54
            'domain_id' => 'Domain',
55
            'source' => 'Source',
56
            'destination' => 'Destination',
57
        ];
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function __toString()
64
    {
65
        return $this->domain->name . ': ' . $this->source . ' => '. $this->destination;
66
    }
67
}
68