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