Completed
Push — master ( 776ca6...8e946b )
by Dmitry
25s
created

DateTimeType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 8 2
A getValue() 0 8 2
1
<?php
2
3
namespace iMega\Formatter;
4
5
class DateTimeType extends GenericType
6
{
7 4
    public static function getData($value)
8
    {
9 4
        if (!$value instanceof \DateTime) {
10 2
            throw new \RuntimeException('It not DateTime');
11
        }
12
13 2
        return $value->format('Y-m-d H:i:s');
14
    }
15
16 4
    public static function getValue($value)
17
    {
18 4
        if (false === $dateTime = date_create_from_format('Y-m-d H:i:s', $value)) {
19 2
            throw new \RuntimeException('String not convert');
20
        }
21
22 2
        return $dateTime;
23
    }
24
}
25