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

DateTimeType::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 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