Passed
Branch master (309757)
by Dispositif
03:20 queued 54s
created

DtoConvertDateTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 3
dl 0
loc 11
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sqlToDateTime() 0 3 2
A dateTimeToSql() 0 3 2
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
}