We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 26 | final class DateTime implements Rule |
||
| 27 | 29 | { |
|
| 28 | 2 | /** |
|
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | 27 | private $format; |
|
| 32 | 1 | ||
| 33 | const EXCEPTIONAL_FORMATS = [ |
||
| 34 | 'c' => 'Y-m-d\TH:i:sP', |
||
| 35 | 26 | 'r' => 'D, d M Y H:i:s O', |
|
| 36 | ]; |
||
| 37 | 26 | ||
| 38 | 5 | public function __construct(string $format = null) |
|
| 42 | 21 | ||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 21 | public function apply($input): Result |
|
| 47 | 7 | { |
|
| 48 | if ($input instanceof DateTimeInterface) { |
||
| 49 | return new Result($this->format === null, $input, $this, array_filter(['format' => $this->format])); |
||
| 50 | 21 | } |
|
| 51 | |||
| 52 | 21 | $scalarValResult = (new ScalarVal())->apply($input); |
|
| 53 | if (!$scalarValResult->isValid()) { |
||
| 54 | return new Result(false, $input, $this, [], $scalarValResult); |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($this->format === null) { |
||
| 58 | return $this->validateWithoutFormat($input); |
||
| 59 | } |
||
| 60 | |||
| 61 | return $this->validateWithFormat($input, $this->format); |
||
| 62 | } |
||
| 63 | |||
| 64 | private function validateWithoutFormat($input): Result |
||
| 68 | |||
| 69 | private function validateWithFormat($input, string $format): Result |
||
| 80 | } |
||
| 81 |