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
03:04
created

DateTime   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 42
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 4
A __construct() 0 3 1
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