| Conditions | 7 |
| Paths | 7 |
| Total Lines | 26 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function validateField(Structure $document, $fieldName, array $params) |
||
| 25 | { |
||
| 26 | $value = $document->get($fieldName); |
||
| 27 | |||
| 28 | if (!$value) { |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | $isValidEmail = filter_var($value, FILTER_VALIDATE_EMAIL); |
||
| 33 | $isValidMX = true; |
||
| 34 | |||
| 35 | if ($isValidEmail && !empty($params['mx'])) { |
||
| 36 | list(, $host) = explode('@', $value); |
||
| 37 | $isValidMX = checkdnsrr($host, 'MX'); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($isValidEmail && $isValidMX) { |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!isset($params['message'])) { |
||
| 45 | $params['message'] = 'Value of field "' . $fieldName . '" is not email in model ' . get_called_class(); |
||
| 46 | } |
||
| 47 | |||
| 48 | $document->addError($fieldName, $this->getName(), $params['message']); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |