EmailLocalPartValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 30
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 3
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\validators;
12
13
use yii\validators\RegularExpressionValidator;
14
15
/**
16
 * Class EmailLocalPart is used to validate Email local parts.
17
 */
18
class EmailLocalPartValidator extends RegularExpressionValidator
19
{
20
    /**
21
     * @var string default validation pattern for the local part
22
     */
23
    public $defaultPattern = '/^[0-9a-z_+-]([0-9a-z\._+-]+)?$/i';
24
25
    /**
26
     * @var string the same as [[defaultPattern]], but allows `*` character.
27
     * Used when [[allowWildCard]] is true.
28
     */
29
    public $defaultWildPattern = '/^(\*|([0-9a-z_+-]([0-9a-z\._+-]+)?))$/i';
30
31
    /**
32
     * @var bool Whether to allow `*` char instead of local part. Defaults to false.
33
     */
34
    public $allowWildCard = false;
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function init()
40
    {
41
        $this->message = \Yii::t('hipanel:hosting', '{attribute} is not a valid local part of email');
42
43
        if ($this->pattern === null) {
44
            $this->pattern = $this->allowWildCard ? $this->defaultWildPattern : $this->defaultPattern;
45
        }
46
    }
47
}
48