Completed
Push — master ( bba925...6f9e63 )
by Radu
07:51
created

DateHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Helpers;
6
7
class DateHelper
8
{
9
    /**
10
    * Format a date, with validation.
11
    */
12
    public static function format(string $date, string $format = 'Y-m-d'): string
13
    {
14
        $dateTime = \DateTime::createFromFormat($format, $date);
15
        if (false === $dateTime) {
16
            throw new \WebServCo\Framework\Exceptions\DateTimeException('Invalid date or format.');
17
        }
18
        return $dateTime->format($format);
19
    }
20
}
21