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