Code Duplication    Length = 26-26 lines in 2 locations

IPv6Validator.php 1 location

@@ 17-42 (lines=26) @@
14
/**
15
 * Class IPv46Validator
16
 */
17
class IPv46Validator 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
		if (!$this->validateValue($string)) {
31
			$this->addError($model, $attribute, \Yii::t('yii', 'This in not valid IPv6 address {sample}', ['sample' => '::1']));
32
			return false;
33
		}
34
		return true;
35
	}
36
37
	public function validateValue($string) {
38
39
		// filter_var suxx
40
		return 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);
41
	}
42
}
43
44
?>

MACValidator.php 1 location

@@ 17-42 (lines=26) @@
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
		if (!$this->validateValue($string)) {
31
			$this->addError($model, $attribute, \Yii::t('yii', 'This in not valid MAC address {sample}', ['sample' => '00:00:00:00:00:01']));
32
			return false;
33
		}
34
		return true;
35
	}
36
37
	public function validateValue($string) {
38
39
		// filter_var suxx
40
		return preg_match('/^([0-9a-F]{1,2}[\.:-]){5}([0-9a-F]{1,2})$/', $string);
41
	}
42
}
43
44
?>