DateHelper::mysqlDateTime()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
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