DateHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 31
rs 10
c 2
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mysqlDate() 0 7 2
A mysqlDateTime() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Helper;
6
7
use DateTime;
8
9
class DateHelper
10
{
11
    public const MYSQL_DATE_FORMAT     = "Y-m-d";
12
    public const MYSQL_DATETIME_FORMAT = "Y-m-d H:i:s";
13
14
    /**
15
     * @param DateTime|null $date
16
     *
17
     * @return string
18
     */
19
    public static function mysqlDate(?DateTime $date = null): string
20
    {
21
        if (!$date) {
22
            $date = new DateTime();
23
        }
24
25
        return $date->format(static::MYSQL_DATE_FORMAT);
26
    }
27
28
    /**
29
     * @param DateTime|null $dateTime
30
     *
31
     * @return string
32
     */
33
    public static function mysqlDateTime(?DateTime $dateTime = null): string
34
    {
35
        if (!$dateTime) {
36
            $dateTime = new DateTime();
37
        }
38
39
        return $dateTime->format(static::MYSQL_DATETIME_FORMAT);
40
    }
41
}
42