Test Failed
Pull Request — master (#23)
by Jean-Christophe
12:28
created

DateTime::reverse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Ubiquity\contents\transformation\transformers;
4
5
use Ubiquity\contents\transformation\TransformerInterface;
6
use Ubiquity\contents\transformation\TransformerViewInterface;
7
use Ubiquity\contents\transformation\TransformerFormInterface;
8
9
/**
10
 * Transform a mysql date to a php DateTime.
11
 * Ubiquity\contents\transformation\transformers$DateTime
12
 * This class is part of Ubiquity
13
 *
14
 * @author jcheron <[email protected]>
15
 * @version 1.0.0
16
 * @since 2.1.1
17
 */
18
class DateTime implements TransformerInterface, TransformerViewInterface, TransformerFormInterface {
19
20
	public static function transform($value) {
21
		if ($value != null)
22
			return new \DateTime ( $value );
23
	}
24
25
	public static function reverse($value) {
26
		if ($value instanceof \DateTime) {
27
			return $value->format ( 'Y-m-d H:i:s' );
28
		}
29
		return $value;
30
	}
31
32
	public static function toView($value) {
33
		return self::reverse ( $value );
34
	}
35
36
	public static function toForm($value) {
37
		if ($value instanceof \DateTime)
38
			return $value->format ( "Y-m-d\TH:i:s" );
39
		return date ( "Y-m-d\TH:i:s", strtotime ( $value ) );
40
	}
41
}
42