Failed Conditions
Push — newinternal ( 216d62...410e59 )
by Simon
05:28 queued 13s
created

smarty_modifier_date()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 4
nc 2
nop 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
/**
10
 * Transforms a date object into a string representation
11
 *
12
 * @param DateTime|DateTimeImmutable $input A date
13
 *
14
 * @return string
15
 * @example {$variable|date} from Smarty
16
 */
17
function smarty_modifier_date($input)
18
{
19
    if (gettype($input) === 'object'
20
        && (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class)
21
    ) {
22
        /** @var $date DateTime|DateTimeImmutable */
23
        $date = $input;
24
        $dateString = $date->format('Y-m-d H:i:s');
25
26
        return $dateString;
27
    }
28
    else {
29
        return $input;
30
    }
31
}