TimeType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToPHPValue() 0 7 1
A getName() 0 4 1
A convertToHydratorValue() 0 16 4
1
<?php
2
3
namespace JhFlexiTime\DBAL\Types;
4
5
use Doctrine\DBAL\Types\TimeType as DoctrineTimeType;
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use JhFlexiTime\DateTime\DateTime;
8
use JhFlexiTime\Stdlib\Hydrator\TypeConversionInterface;
9
10
/**
11
 * Class TimeType
12
 * @package JhFlexiTime\DBAL\Types
13
 * @author Aydin Hassan <[email protected]>
14
 */
15
class TimeType extends DoctrineTimeType implements TypeConversionInterface
16
{
17
    /**
18
     * @param mixed $value
19
     * @param AbstractPlatform $platform
20
     * @return DateTime|mixed
21
     */
22
    public function convertToPHPValue($value, AbstractPlatform $platform)
23
    {
24
        $dateTime = parent::convertToPHPValue($value, $platform);
25
        $return = new DateTime();
26
        $return->setTimestamp($dateTime->getTimestamp());
27
        return $return;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getName()
34
    {
35
        return 'time';
36
    }
37
38
    /**
39
     * @param string $value
40
     * @return DateTime
41
     */
42
    public function convertToHydratorValue($value)
43
    {
44
        if ('' === $value) {
45
            return null;
46
        }
47
48
        if (is_int($value)) {
49
            $dateTime = new DateTime();
50
            $dateTime->setTimestamp($value);
51
            $value = $dateTime;
52
        } elseif (is_string($value)) {
53
            $value = new DateTime($value);
54
        }
55
56
        return $value;
57
    }
58
}
59