We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 6.0163 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | 27 | public function validate($input) |
|
| 26 | { |
||
| 27 | 27 | if ($input instanceof DateTimeInterface) { |
|
| 28 | 2 | return true; |
|
| 29 | } |
||
| 30 | |||
| 31 | 25 | if (!is_scalar($input)) { |
|
| 32 | 1 | return false; |
|
| 33 | } |
||
| 34 | |||
| 35 | 24 | $allowedFormat = '/[djSFmMnYy\W]+$/'; |
|
| 36 | 24 | if(!preg_match($allowedFormat, $this->format)) { |
|
| 37 | 20 | return false; |
|
| 38 | } |
||
| 39 | |||
| 40 | 4 | $inputString = (string) $input; |
|
| 41 | 4 | if (is_null($this->format)) { |
|
| 42 | return false !== strtotime($inputString); |
||
| 43 | } |
||
| 44 | |||
| 45 | 4 | $info = date_parse_from_format($this->format, $inputString); |
|
| 46 | |||
| 47 | 4 | return $info['error_count'] === 0 && $info['warning_count'] === 0; |
|
| 48 | } |
||
| 49 | } |
||
| 50 |