Code Duplication    Length = 20-21 lines in 3 locations

IPv4Validator.php 1 location

@@ 17-37 (lines=21) @@
14
/**
15
 * Class IPv4Validator
16
 */
17
class IPv4Validator extends Validator {
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function init() {
22
		parent::init();
23
		if ($this->message === null) {
24
			$this->message = Yii::t('yii', "{attribute} is invalid.");
25
		}
26
	}
27
28
	public function validateAttribute($model, $attribute) {
29
		$string = $model->{$attribute};
30
31
		// filter_var suxx
32
		if (!preg_match('/^((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?1)){3}\z/', $string)) {
33
			$this->addError($model, $attribute, Yii::t('yii', 'This in not valid IPv4 address {sample}', ['sample' => '127.0.0.1']));
34
			return false;
35
		}
36
	}
37
}
38
39
?>

IPv6Validator.php 1 location

@@ 17-36 (lines=20) @@
14
/**
15
 * Class IPv46alidator
16
 */
17
class IPv46alidator extends Validator {
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function init() {
22
		parent::init();
23
		if ($this->message === null) {
24
			$this->message = Yii::t('yii', "{attribute} is invalid.");
25
		}
26
	}
27
28
	public function validateAttribute($model, $attribute) {
29
		$string = $model->{$attribute};
30
31
		// filter_var suxx
32
		if (!preg_match('/^(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|((2[0-4]|1\d|[1-9])?\d|25[0-5])(\.(?7)){3})\z/i', $string)) {
33
			$this->addError($model, $attribute, Yii::t('yii', 'This in not valid IPv6 address {sample}', ['sample' => '::1']));
34
		}
35
	}
36
}
37
38
?>

MACValidator.php 1 location

@@ 17-37 (lines=21) @@
14
/**
15
 * Class MACValidator
16
 */
17
class MACValidator extends Validator {
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function init() {
22
		parent::init();
23
		if ($this->message === null) {
24
			$this->message = Yii::t('yii', "{attribute} is invalid.");
25
		}
26
	}
27
28
	public function validateAttribute($model, $attribute) {
29
		$string = $model->{$attribute};
30
31
		// filter_var suxx
32
		if (!preg_match('/^([0-9a-F]{1,2}[\.:-]){5}([0-9a-F]{1,2})$/', $string)) {
33
			$this->addError($model, $attribute, Yii::t('yii', 'This in not valid MAC address {sample}', ['sample' => '00:00:00:00:00:01']));
34
			return false;
35
		}
36
	}
37
}
38
39
?>