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