Completed
Push — master ( 63117e...c0048b )
by Sebastian
02:30
created

Date::sanitize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types = 1);
11
12
namespace Linna\Filter\Rules;
13
14
use DateTime;
15
16
/**
17
 * Check required.
18
 */
19
class Date
20
{
21
    /**
22
     * @var DateTime Valid date.
23
     */
24
    private $date;
25
    
26
    /**
27
     * Validate.
28
     *
29
     * @return bool
30
     */
31
    public function validate($received, string $format): bool
32
    {
33
        if (($this->date = date_create_from_format($format, $received))) {
34
            return false;
35
        }
36
        
37
        return true;
38
    }
39
    
40
    /**
41
     * Sanitize.
42
     *
43
     * @param mixed $value
44
     */
45
    public function sanitize(&$value)
46
    {
47
        $value = $this->date;
48
    }
49
}
50