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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B filterInterval() 0 17 6
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