Completed
Branch newinternal (cdd491)
by Simon
04:39
created

modifier.date.php ➔ smarty_modifier_date()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.2
1
<?php
2
3
/**
4
 * Transforms a date object into a string representation
5
 *
6
 * @param DateTime|DateTimeImmutable $input A date
7
 *
8
 * @return string
9
 * @example {$variable|date} from Smarty
10
 */
11
function smarty_modifier_date($input)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
12
{
13
	if (gettype($input) === 'object'
14
		&& (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class)
15
	) {
16
		/** @var $date DateTime|DateTimeImmutable */
17
		$date = $input;
18
		$dateString = $date->format('Y-m-d H:i:s');
19
20
		return $dateString;
21
	}
22
	else {
23
		return $input;
24
	}
25
}