| Conditions | 5 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 26 | public function validate($value, array $parameters) { |
||
| 27 | |||
| 28 | $this->validateMinParameterCount('beforeDateTime', 1, $parameters); |
||
| 29 | |||
| 30 | $format = 'Y-m-d H:i:s'; |
||
| 31 | if (count($parameters) > 1) { |
||
| 32 | $format = $parameters[1]; |
||
| 33 | } |
||
| 34 | $compareDate = \DateTime::createFromFormat($format, $parameters[0]); |
||
| 35 | if ($compareDate === false) { |
||
| 36 | throw new ValidationException('"beforeDateTime" expects a date of the format ' . $format . '.'); |
||
| 37 | } |
||
| 38 | |||
| 39 | if (in_array($value, array('', null), true)) { |
||
| 40 | return true; |
||
| 41 | } |
||
| 42 | |||
| 43 | $date = \DateTime::createFromFormat($format, $value); |
||
| 44 | if ($date === false) { |
||
| 45 | return false; |
||
| 46 | } |
||
| 47 | return $this->compare($date, $compareDate); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |