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

Passed
Push — master ( 2007c7...fb2eba )
by Henrique
02:24
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
    /**
31
     * @var string|null
32
     */
33
    private $format;
34
35
    /**
36
     * Initializes the rule.
37
     *
38
     * @param string|null $format
39
     */
40 9
    public function __construct(string $format = null)
41
    {
42 9
        $this->format = $format;
43 9
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 37
    public function validate($input): bool
49
    {
50 37
        if ($input instanceof DateTimeInterface) {
51 4
            return null === $this->format;
52
        }
53
54 33
        if (!is_scalar($input)) {
55 2
            return false;
56
        }
57
58 31
        if (null === $this->format) {
59 12
            return false !== strtotime((string) $input);
60
        }
61
62 19
        return $this->isDateTime($this->format, (string) $input);
63
    }
64
}
65