• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / docker-symfony-api / #79

pending completion
#79

push

DKravtsov
Updated documentation, composer dependencies, fixed php-cs-fixer code quality tool.

1475 of 2655 relevant lines covered (55.56%)

23.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/General/Domain/Doctrine/DBAL/Types/UTCDateTimeType.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\General\Domain\Doctrine\DBAL\Types;
6

7
use DateTime;
8
use DateTimeInterface;
9
use DateTimeZone;
10
use Doctrine\DBAL\Platforms\AbstractPlatform;
11
use Doctrine\DBAL\Types\ConversionException;
12
use Doctrine\DBAL\Types\DateTimeType;
13

14
/**
15
 * Class UTCDateTimeType
16
 *
17
 * @see http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.html
18
 *
19
 * @package App\General
20
 */
21
class UTCDateTimeType extends DateTimeType
22
{
23
    private static ?DateTimeZone $utc;
24

25
    /**
26
     * {@inheritdoc}
27
     *
28
     * @throws ConversionException
29
     */
30
    public function convertToDatabaseValue($value, AbstractPlatform $platform): string
31
    {
32
        if ($value instanceof DateTime) {
×
33
            $value->setTimezone($this->getUtcDateTimeZone());
×
34
        }
35

36
        return (string)parent::convertToDatabaseValue($value, $platform);
×
37
    }
38

39
    /**
40
     * @param T $value
41
     *
42
     * @return (T is null ? null : DateTimeInterface)
43
     *
44
     * @template T
45
     *
46
     * @throws ConversionException
47
     */
48
    public function convertToPHPValue($value, AbstractPlatform $platform): DateTimeInterface|null
49
    {
50
        if ($value instanceof DateTime) {
×
51
            $value->setTimezone($this->getUtcDateTimeZone());
×
52
        } elseif ($value !== null) {
×
53
            $converted = DateTime::createFromFormat(
×
54
                $platform->getDateTimeFormatString(),
×
55
                (string)$value,
×
56
                $this->getUtcDateTimeZone()
×
57
            );
×
58

59
            $value = $this->checkConvertedValue((string)$value, $platform, $converted !== false ? $converted : null);
×
60
        }
61

62
        return parent::convertToPHPValue($value, $platform);
×
63
    }
64

65
    /**
66
     * Method to initialize DateTimeZone as in UTC.
67
     */
68
    private function getUtcDateTimeZone(): DateTimeZone
69
    {
70
        return self::$utc ??= new DateTimeZone('UTC');
×
71
    }
72

73
    /**
74
     * Method to check if conversion was successfully or not.
75
     *
76
     * @throws ConversionException
77
     */
78
    private function checkConvertedValue(string $value, AbstractPlatform $platform, ?DateTime $converted): DateTime
79
    {
80
        if ($converted instanceof DateTime) {
×
81
            return $converted;
×
82
        }
83

84
        throw ConversionException::conversionFailedFormat(
×
85
            $value,
×
86
            $this->getName(),
×
87
            $platform->getDateTimeFormatString()
×
88
        );
×
89
    }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc