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 (#684)
by Emmerson
04:39
created

Date::validate()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7

Importance

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