Completed
Pull Request — master (#1)
by Artem
01:09
created

DateTimeHelper::convertDateTimeToImmutable()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/*
3
 * This file is part of the DateTime library
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\DateTime;
14
15
/**
16
 * DateTimeHelper.
17
 *
18
 * @author Artem Henvald <[email protected]>
19
 */
20
class DateTimeHelper
21
{
22
    /**
23
     * @param \DateTimeInterface $date
24
     *
25
     * @return \DateTimeImmutable
26
     */
27
    public static function convertDateTimeToImmutable(\DateTimeInterface $date): \DateTimeImmutable
28
    {
29
        if (!$date instanceof \DateTimeImmutable && $date instanceof \DateTime) {
30
            return \DateTimeImmutable::createFromMutable($date);
31
        }
32
33
        return $date;
34
    }
35
}
36