| Conditions | 8 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function validateField(Structure $document, $fieldName, array $params) |
||
| 25 | { |
||
| 26 | $value = $document->get($fieldName); |
||
| 27 | if (!$value) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (!isset($params['min'])) { |
||
| 32 | throw new Exception('Minimum value of range not specified'); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (!isset($params['max'])) { |
||
| 36 | throw new Exception('Maximum value of range not specified'); |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($value < $params['min']) { |
||
| 40 | if (empty($params['minMessage'])) { |
||
| 41 | $params['minMessage'] = 'Field "' . $fieldName . '" less than minimal value of range in ' . get_called_class(); |
||
| 42 | } |
||
| 43 | $document->addError($fieldName, $this->getName(), $params['minMessage']); |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($value > $params['max']) { |
||
| 47 | if (empty($params['maxMessage'])) { |
||
| 48 | $params['maxMessage'] = 'Field "' . $fieldName . '" less than minimal value of range in ' . get_called_class(); |
||
| 49 | } |
||
| 50 | $document->addError($fieldName, $this->getName(), $params['maxMessage']); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 |