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::validate()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 8.8571
cc 5
eloc 8
nc 3
nop 1
crap 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