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 — 0.9 (#692)
by
unknown
02:58
created

Date::validate()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 8.5906
cc 6
eloc 14
nc 7
nop 1
crap 6
1
<?php
2
namespace Respect\Validation\Rules;
3
4
use DateTime;
5
6
class Date extends AbstractRule
7
{
8
    public $format = null;
9
10 22
    public function __construct($format = null)
11
    {
12 22
        $this->format = $format;
13 22
    }
14
15 20
    public function validate($input)
16
    {
17 20
        if ($input instanceof DateTime) {
18 1
            return true;
19 19
        } elseif (!is_string($input)) {
20 1
            return false;
21 18
        } elseif (is_null($this->format)) {
22 2
            return false !== strtotime($input);
23
        }
24
25
        $exceptionalFormats = array(
26 16
            'c'     =>  'Y-m-d\TH:i:sP',
27 16
            'r'     =>  'D, d M Y H:i:s O',
28 16
        );
29
30 16
        if (in_array($this->format, array_keys($exceptionalFormats))) {
31 7
            $this->format = $exceptionalFormats[ $this->format ];
32 7
        }
33
34 16
        $info = date_parse_from_format($this->format, $input);
35
36 16
        return ($info['error_count'] === 0 && $info['warning_count'] === 0);
37
    }
38
}
39