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 | { |
||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $format; |
||
| 32 | |||
| 33 | const EXCEPTIONAL_FORMATS = [ |
||
| 34 | 'c' => 'Y-m-d\TH:i:sP', |
||
| 35 | 'r' => 'D, d M Y H:i:s O', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | 9 | public function __construct(string $format = null) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 117 | public function apply($input): Result |
|
| 47 | { |
||
| 48 | 117 | if ($input instanceof DateTimeInterface) { |
|
| 49 | 12 | return new Result($this->format === null, $input, $this, array_filter(['format' => $this->format])); |
|
| 50 | } |
||
| 51 | |||
| 52 | 105 | $scalarValResult = (new ScalarVal())->apply($input); |
|
| 53 | 105 | if (!$scalarValResult->isValid()) { |
|
| 54 | 13 | return new Result(false, $input, $this, [], $scalarValResult); |
|
| 55 | } |
||
| 56 | |||
| 57 | 92 | if ($this->format === null) { |
|
| 58 | 16 | return $this->validateWithoutFormat($input); |
|
| 59 | } |
||
| 60 | |||
| 61 | 76 | return $this->validateWithFormat($input, $this->format); |
|
| 62 | } |
||
| 63 | |||
| 64 | 16 | private function validateWithoutFormat($input): Result |
|
| 68 | |||
| 69 | 76 | private function validateWithFormat($input, string $format): Result |
|
| 80 | } |
||
| 81 |