Code Duplication    Length = 42-43 lines in 2 locations

src/Types/DateType.php 1 location

@@ 29-70 (lines=42) @@
26
/**
27
 * @package Limoncello\Flute
28
 */
29
class DateType extends BaseDateType
30
{
31
    use TypeTrait;
32
33
    /** Type name */
34
    const NAME = 'limoncelloDate';
35
36
    /**
37
     * @inheritdoc
38
     *
39
     * @return DateTime|null
40
     *
41
     * @throws ConversionException
42
     * @throws Exception
43
     *
44
     * @SuppressWarnings(PHPMD.StaticAccess)
45
     */
46
    public function convertToPHPValue($value, AbstractPlatform $platform)
47
    {
48
        $result = null;
49
50
        if ($value !== null && ($dateOrNull = parent::convertToPHPValue($value, $platform)) !== null) {
51
            // despite the name it's not null already
52
            $result = DateTime::createFromDateTime($dateOrNull);
53
        }
54
55
        return $result;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     *
61
     * @throws ConversionException
62
     */
63
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
64
    {
65
        return parent::convertToDatabaseValue(
66
            $this->convertToDateTimeFromString($value, $platform->getDateTimeFormatString(), static::NAME),
67
            $platform
68
        );
69
    }
70
}
71

src/Types/DateTimeType.php 1 location

@@ 31-73 (lines=43) @@
28
/**
29
 * @package Limoncello\Flute
30
 */
31
class DateTimeType extends BaseDateTimeType
32
{
33
    use TypeTrait;
34
35
    /** Type name */
36
    const NAME = 'limoncelloDateTime';
37
38
    /**
39
     * @inheritdoc
40
     *
41
     * @return DateTime|null
42
     *
43
     * @throws ConversionException
44
     * @throws Exception
45
     *
46
     * @SuppressWarnings(PHPMD.StaticAccess)
47
     */
48
    public function convertToPHPValue($value, AbstractPlatform $platform)
49
    {
50
        $result = null;
51
52
        if ($value !== null && ($dateTimeOrNull = parent::convertToPHPValue($value, $platform)) !== null) {
53
            assert($dateTimeOrNull instanceof DateTimeInterface);
54
            // despite the name it's not null already
55
            $result = DateTime::createFromDateTime($dateTimeOrNull);
56
        }
57
58
        return $result;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     *
64
     * @throws ConversionException
65
     */
66
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
67
    {
68
        return parent::convertToDatabaseValue(
69
            $this->convertToDateTimeFromString($value, $platform->getDateTimeFormatString(), static::NAME),
70
            $platform
71
        );
72
    }
73
}
74