| Total Complexity | 6 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 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 ($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) |
||
| 50 | }} |