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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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