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

systemsdk / docker-symfony-api / #148

05 Jul 2025 05:45PM UTC coverage: 43.891% (-0.01%) from 43.903%
#148

push

DKravtsov
doctrine 3.4, updated composer dependencies.

0 of 6 new or added lines in 5 files covered. (0.0%)

1631 of 3716 relevant lines covered (43.89%)

18.93 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 DateTimeZone;
9
use Doctrine\DBAL\Exception;
10
use Doctrine\DBAL\Platforms\AbstractPlatform;
11
use Doctrine\DBAL\Types\ConversionException;
12
use Doctrine\DBAL\Types\DateTimeType;
13
use Doctrine\DBAL\Types\Exception\ValueNotConvertible;
14
use Override;
15

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 = null;
24

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

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

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

62
            $value = $this->checkConvertedValue((string)$value, $platform, $converted !== false ? $converted : null);
×
63
        }
64

65
        return parent::convertToPHPValue($value, $platform);
×
66
    }
67

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

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

NEW
88
        throw ValueNotConvertible::new(
×
89
            $value,
×
90
            self::lookupName($this),
×
91
            $platform->getDateTimeFormatString()
×
92
        );
×
93
    }
94
}
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

© 2025 Coveralls, Inc