Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#913)
by Henrique
02:41 queued 20s
created

DateTime::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use function is_scalar;
17
use function strtotime;
18
use DateTimeInterface;
19
use Respect\Validation\Helpers\DateTimeHelper;
20
21
/**
22
 * @author Alexandre Gomes Gaigalas <[email protected]>
23
 * @author Emmerson Siqueira <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 */
26
final class DateTime extends AbstractRule
27
{
28
    use DateTimeHelper;
29
30
    private const EXCEPTIONAL_FORMATS = [
31
        'c' => 'Y-m-d\TH:i:sP',
32
        'r' => 'D, d M Y H:i:s O',
33
    ];
34
35
    /**
36
     * @var string|null
37
     */
38
    private $format;
39
40
    /**
41
     * Initializes the rule.
42
     *
43
     * @param string|null $format
44
     */
45 3
    public function __construct(string $format = null)
46
    {
47 3
        $this->format = self::EXCEPTIONAL_FORMATS[$format] ?? $format;
48 3
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 29
    public function validate($input): bool
54
    {
55 29
        if ($input instanceof DateTimeInterface) {
56 4
            return null === $this->format;
57
        }
58
59 25
        if (!is_scalar($input)) {
60 2
            return false;
61
        }
62
63 23
        if (null === $this->format) {
64 12
            return false !== strtotime((string) $input);
65
        }
66
67 11
        return $this->isValidDateTime($this->format, (string) $input);
68
    }
69
}
70