Birthdate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 24
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 3
A toDatabase() 0 3 1
A isSame() 0 3 1
1
<?php
2
3
namespace Validate;
4
5
use Carbon\Carbon;
6
7
class Birthdate extends Date implements \Validate\Contracts\Validate
8
{
9
    public static function toDatabase($birthdate)
10
    {
11
        return parent::toDatabase($birthdate);
12
    }
13
14
    public static function validate($birthdate)
15
    {   
16
        if (!parent::validate($birthdate)) {
17
            return false;
18
        }
19
20
        $birthdate = Carbon::createFromFormat('Y-m-d', self::toDatabase($birthdate));
21
        if ($birthdate->greaterThan(Carbon::now())) {
22
            return false;
23
        }
24
25
        return true;
26
    }
27
28
    public static function isSame(string $to, string $from)
29
    {
30
        return (self::toDatabase($to)===self::toDatabase($from));
31
    }
32
33
}
34