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
Pull Request — master (#910)
by Henrique
02:24
created

DateTime   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
dl 0
loc 37
ccs 15
cts 16
cp 0.9375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B validate() 0 28 6
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 DateTimeInterface;
17
18
class DateTime extends AbstractRule
19
{
20
    public $format = null;
21
22 10
    public function __construct($format = null)
23
    {
24 10
        $this->format = $format;
25 10
    }
26
27 10
    public function validate($input): bool
28
    {
29 10
        if ($input instanceof DateTimeInterface) {
30 2
            return true;
31
        }
32
33 8
        if (!is_scalar($input)) {
34 1
            return false;
35
        }
36
37 7
        $inputString = (string) $input;
38
39 7
        if (is_null($this->format)) {
40 5
            return false !== strtotime($inputString);
41
        }
42
43
        $exceptionalFormats = [
44 2
            'c' => 'Y-m-d\TH:i:sP',
45
            'r' => 'D, d M Y H:i:s O',
46
        ];
47
48 2
        if (in_array($this->format, array_keys($exceptionalFormats))) {
49
            $this->format = $exceptionalFormats[$this->format];
50
        }
51
52 2
        $info = date_parse_from_format($this->format, $inputString);
53
54 2
        return 0 === $info['error_count'] && 0 === $info['warning_count'];
55
    }
56
}
57