We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 6.0163 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 33 | public function validate($input) |
|
| 26 | { |
||
| 27 | 33 | if ($input instanceof DateTimeInterface) { |
|
| 28 | 2 | return true; |
|
| 29 | } |
||
| 30 | |||
| 31 | 31 | if (!is_scalar($input)) { |
|
| 32 | return false; |
||
| 33 | } |
||
| 34 | |||
| 35 | 31 | if (is_null($this->format)) { |
|
| 36 | 5 | return false !== strtotime((string) $input); |
|
| 37 | } |
||
| 38 | |||
| 39 | $exceptionalFormats = [ |
||
| 40 | 26 | 'c' => 'Y-m-d\TH:i:sP', |
|
| 41 | 'r' => 'D, d M Y H:i:s O', |
||
| 42 | ]; |
||
| 43 | |||
| 44 | 26 | $format = $this->format; |
|
| 45 | 26 | if (isset($exceptionalFormats[$format])) { |
|
| 46 | 8 | $format = $exceptionalFormats[$format]; |
|
| 47 | } |
||
| 48 | |||
| 49 | 26 | $info = date_parse_from_format($format, (string) $input); |
|
| 50 | |||
| 51 | 26 | return $info['error_count'] === 0 && $info['warning_count'] === 0; |
|
| 52 | } |
||
| 53 | } |
||
| 54 |