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 ( 9460a4...cca733 )
by Henrique
04:50
created

MinimumAge   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
B validate() 0 16 5
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 Respect\Validation\Exceptions\ComponentException;
16
17
class MinimumAge extends AbstractRule
18
{
19
    public $age = null;
20
    public $format = null;
21
22 13
    public function __construct($age, $format = null)
23
    {
24 13
        if (!filter_var($age, FILTER_VALIDATE_INT)) {
25 1
            throw new ComponentException('The age must be a integer value.');
26
        }
27
28 12
        $this->age = $age;
29 12
        $this->format = $format;
30 12
    }
31
32 12
    public function validate($input)
33
    {
34 12
        if ($input instanceof DateTime) {
35 4
            $birthday = new \DateTime('now - '.$this->age.' year');
36
37 4
            return $birthday > $input;
38
        }
39
40 8
        if (!is_string($input) || (is_null($this->format) && false === strtotime($input))) {
41 2
            return false;
42
        }
43
44 6
        $age = ((date('Ymd') - date('Ymd', strtotime($input))) / 10000);
45
46 6
        return $age >= $this->age;
47
    }
48
}
49