| Total Complexity | 8 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
||
| 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() |
||
| 79 | ]; |
||
| 80 | } |
||
| 81 | } |
||
| 82 |