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 | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 6.0163 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | 10 | public function validate($input): bool |
|
| 28 | { |
||
| 29 | 10 | if ($input instanceof DateTimeInterface) { |
|
| 30 | 2 | return true; |
|
| 31 | } |
||
| 32 | |||
| 33 | 8 | if (!is_scalar($input)) { |
|
| 34 | 1 | return false; |
|
| 35 | } |
||
| 36 | |||
| 37 | 7 | $inputString = (string) $input; |
|
| 38 | |||
| 39 | 7 | if (is_null($this->format)) { |
|
| 40 | 5 | return false !== strtotime($inputString); |
|
| 41 | } |
||
| 42 | |||
| 43 | $exceptionalFormats = [ |
||
| 44 | 2 | 'c' => 'Y-m-d\TH:i:sP', |
|
| 45 | 'r' => 'D, d M Y H:i:s O', |
||
| 46 | ]; |
||
| 47 | |||
| 48 | 2 | if (in_array($this->format, array_keys($exceptionalFormats))) { |
|
| 49 | $this->format = $exceptionalFormats[$this->format]; |
||
| 50 | } |
||
| 51 | |||
| 52 | 2 | $info = date_parse_from_format($this->format, $inputString); |
|
| 53 | |||
| 54 | 2 | return 0 === $info['error_count'] && 0 === $info['warning_count']; |
|
| 55 | } |
||
| 57 |