Passed
Push — master ( 89a559...309757 )
by Dispositif
02:41
created

DtoConvertDateTrait::sqlToDateTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\Models;
11
12
use DateTime;
13
use DateTimeInterface;
14
15
/**
16
 * Hack because the minimalist ORM does not support DateTime<>string conversion.
17
 */
18
trait DtoConvertDateTrait
19
{
20
    // 2023-02-12 15:04:53
21
    public static function sqlToDateTime(?string $string): ?DateTime
22
    {
23
        return $string ? DateTime::createFromFormat('Y-m-d H:i:s', $string) : null;
24
    }
25
26
    public static function dateTimeToSql(?DateTimeInterface $date): ?string
27
    {
28
        return $date ? $date->format('Y-m-d H:i:s') : null;
29
    }
30
}