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

Passed
Pull Request — master (#904)
by Jens
02:11
created

AbstractInterval::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use DateTimeImmutable;
17
use Exception;
18
19
abstract class AbstractInterval extends AbstractRule
20
{
21
    public $interval;
22
    public $inclusive;
23
24
    public function __construct($interval, $inclusive = true)
25
    {
26
        $this->interval = $interval;
27
        $this->inclusive = $inclusive;
28
    }
29
30
    protected function filterInterval($value)
31
    {
32
        if (!is_string($value) || is_numeric($value) || empty($value)) {
33
            return $value;
34
        }
35
36
        if (1 == mb_strlen($value)) {
37
            return $value;
38
        }
39
40
        try {
41
            return new DateTimeImmutable($value);
42
        } catch (Exception $e) {
43
            // Pokémon Exception Handling
44
        }
45
46
        return $value;
47
    }
48
}
49