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
Push — master ( 38aedd...6ee977 )
by Henrique
09:58
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 23
21
    public function __construct($format = null)
22 23
    {
23 23
        $this->format = $format;
24
    }
25 23
26
    public function validate($input)
27 23
    {
28 1
        if ($input instanceof DateTimeInterface
29 22
            || $input instanceof DateTime) {
30 1
            return true;
31 21
        }
32 5
33
        if (!is_scalar($input)) {
34
            return false;
35
        }
36 16
37 16
        $inputString = (string) $input;
38 16
39
        if (is_null($this->format)) {
40 16
            return false !== strtotime($inputString);
41 7
        }
42 7
43
        $exceptionalFormats = [
44 16
            'c' => 'Y-m-d\TH:i:sP',
45
            'r' => 'D, d M Y H:i:s O',
46 16
        ];
47
48
        if (in_array($this->format, array_keys($exceptionalFormats))) {
49
            $this->format = $exceptionalFormats[$this->format];
50
        }
51
52
        $info = date_parse_from_format($this->format, $inputString);
53
54
        return ($info['error_count'] === 0 && $info['warning_count'] === 0);
55
    }
56
}
57