Passed
Pull Request — master (#13)
by
unknown
02:17
created

DateOfBirth::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Skrill\ValueObject;
6
7
use Skrill\ValueObject\Traits\ValueToStringTrait;
8
9
/**
10
 * Class DateOfBirth
11
 *
12
 * Value object for Customer Verification Service.
13
 * The customer verification service is used to check if one of your customers, identified by an email
14
 * address or customer ID, is registered with Skrill (i.e. the customer already has an active Skrill Digital
15
 * Wallet account).You can also verify information that you hold about the customer against Skrill’s
16
 * registration records.
17
 *
18
 * https://www.skrill.com/fileadmin/content/pdf/Skrill_Customer_Verification_Service_Guide_v1.1__1_.pdf
19
 *
20
 */
21
final class DateOfBirth
22
{
23
    use ValueToStringTrait;
24
25
    /**
26
     * Date of birth of the customer. The format is YYYYMMDD.
27
     * Only numeric values are accepted t e.g. 1st December 1970 = 19701201
28
     * @param string $value
29
     */
30
    public function __construct(string $value = null)
31
    {
32
        $this->value = '';
33
        if (!empty($value) && $this->validateDateBefore(trim($value), '-18 YEARS')) {
34
            $this->value = (new \DateTime(trim($value)))->format('Ymd');
35
        }
36
    }
37
38
    /**
39
     * Validate the date is before a given date
40
     * @param  string  $vtime
41
     * @param  string  $ptime
42
     * @return bool
43
     */
44
    protected function validateDateBefore($vtime, $ptime)
45
    {
46
        return strtotime($vtime) < strtotime($ptime);
47
    }
48
}
49