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 (#825)
by Wouter
03:35
created

Date::validate()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

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