Test Failed
Pull Request — master (#97)
by Gildonei
03:38
created

DateTime::reverse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
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 3
	public static function transform($value) {
21 3
		if ($value != null)
22 3
			return new \DateTime ( $value );
23 1
	}
24
25 3
	public static function reverse($value) {
26 3
		if ($value instanceof \DateTime) {
27
			return $value->format ( 'Y-m-d H:i:s' );
28
		}
29 3
		return $value;
30
	}
31
32 3
	public static function toView($value) {
33 3
		return self::reverse ( $value );
34
	}
35
36 2
	public static function toForm($value) {
37 2
		if ($value instanceof \DateTime)
38
			return $value->format ( 'Y-m-d\TH:i:s' );
39 2
		return date ( 'Y-m-d\TH:i:s', strtotime ( $value ) );
40
	}
41
}
42