| Conditions | 8 |
| Paths | 7 |
| Total Lines | 32 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public function isValid($input = null) |
||
| 26 | { |
||
| 27 | if ($input === null || $input === '') { |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | $input = (string) $input; |
||
| 32 | |||
| 33 | PhpDateTime::createFromFormat(static::FORMAT, $input); |
||
| 34 | $errors = PhpDateTime::getLastErrors(); |
||
| 35 | |||
| 36 | if ($errors === false) { |
||
| 37 | return true; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($errors['error_count'] > 0) { |
||
| 41 | $this->violations[] = 'format'; |
||
| 42 | |||
| 43 | return false; |
||
| 44 | } |
||
| 45 | |||
| 46 | foreach ($errors['warnings'] as $warning) { |
||
| 47 | if ($warning === 'The parsed date was invalid') { |
||
| 48 | $this->violations[] = 'date'; |
||
| 49 | } elseif ($warning === 'The parsed time was invalid') { |
||
| 50 | $this->violations[] = 'time'; |
||
| 51 | } else { |
||
| 52 | $this->violations[] = 'format'; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | return !$this->hasViolations(); |
||
| 57 | } |
||
| 59 |