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

LeapDate::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
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 DateTimeImmutable;
15
use DateTimeInterface;
16
17
class LeapDate extends AbstractRule
18
{
19
    public $format = null;
20
21 5
    public function __construct($format)
22
    {
23 5
        $this->format = $format;
24 5
    }
25
26 5
    public function validate($input)
27
    {
28 5
        if (is_string($input)) {
29 2
            $date = DateTimeImmutable::createFromFormat($this->format, $input);
30 3
        } elseif ($input instanceof DateTimeInterface) {
31 2
            $date = $input;
32
        } else {
33 1
            return false;
34
        }
35
36
        // Dates that aren't leap will aways be rounded
37 4
        return $date->format('m-d') == '02-29';
38
    }
39
}
40