Date   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 32
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 21 5
1
<?php
2
3
namespace Kontrolio\Rules\Core;
4
5
use Kontrolio\Rules\AbstractRule;
6
7
/**
8
 * Date validation rule.
9
 *
10
 * @package Kontrolio\Rules\Core
11
 */
12
class Date extends AbstractRule
13
{
14
    const PATTERN = '/^(\d{4})-(\d{2})-(\d{2})$/';
15
16
    /**
17
     * Validates input.
18
     *
19
     * @param mixed $input
20
     *
21
     * @return bool
22
     */
23
    public function isValid($input = null)
24
    {
25
        if ($input === null || $input === '') {
26
            return false;
27
        }
28
29
        $input = (string) $input;
30
31
        if (!preg_match(static::PATTERN, $input, $matches)) {
32
            $this->violations[] = 'format';
33
34
            return false;
35
        }
36
37
        if (!checkdate($matches[2], $matches[3], $matches[1])) {
38
            $this->violations[] = 'date';
39
40
            return false;
41
        }
42
43
        return true;
44
    }
45
}
46