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 (#827)
by Henrique
03:22
created

DateTime::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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
namespace Respect\Validation\Rules;
13
14
use DateTimeInterface;
15
16
class DateTime extends AbstractRule
17
{
18
    public $format = null;
19
20 29
    public function __construct($format = null)
21
    {
22 29
        $this->format = $format;
23 29
    }
24
25 29
    public function validate($input)
26
    {
27 29
        if ($input instanceof DateTimeInterface) {
28 2
            return true;
29
        }
30
31 27
        if (!is_scalar($input)) {
32 1
            return false;
33
        }
34
35 26
        $inputString = (string) $input;
36
37 26
        if (is_null($this->format)) {
38 5
            return false !== strtotime($inputString);
39
        }
40
41
        $exceptionalFormats = [
42 21
            'c' => 'Y-m-d\TH:i:sP',
43
            'r' => 'D, d M Y H:i:s O',
44
        ];
45
46 21
        if (in_array($this->format, array_keys($exceptionalFormats))) {
47 7
            $this->format = $exceptionalFormats[$this->format];
48
        }
49
50 21
        $info = date_parse_from_format($this->format, $inputString);
51
52 21
        return $info['error_count'] === 0 && $info['warning_count'] === 0;
53
    }
54
}
55