| Conditions | 5 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 45 | 8 | public function validate($input): bool |
|
| 46 | { |
||
| 47 | 8 | if ($input instanceof DateTime) { |
|
| 48 | 1 | return true; |
|
| 49 | } |
||
| 50 | |||
| 51 | 7 | if (!is_string($input)) { |
|
| 52 | 1 | return false; |
|
| 53 | } |
||
| 54 | |||
| 55 | 6 | if (null === $this->format) { |
|
| 56 | 2 | return false !== strtotime($input); |
|
| 57 | } |
||
| 58 | |||
| 59 | 4 | $dateFromFormat = DateTime::createFromFormat($this->format, $input); |
|
| 60 | |||
| 61 | 4 | return $dateFromFormat |
|
| 62 | 4 | && $input === date($this->format, $dateFromFormat->getTimestamp()); |
|
| 63 | } |
||
| 78 |