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

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

23.59 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\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Types\ConversionException;
11
use Doctrine\DBAL\Types\DateTimeType;
12

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

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

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

38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws ConversionException
42
     */
43
    public function convertToPHPValue($value, AbstractPlatform $platform): mixed
44
    {
45
        if ($value instanceof DateTime) {
×
46
            $value->setTimezone($this->getUtcDateTimeZone());
×
47
        } elseif ($value !== null) {
×
48
            $converted = DateTime::createFromFormat(
×
49
                $platform->getDateTimeFormatString(),
×
50
                (string)$value,
×
51
                $this->getUtcDateTimeZone()
×
52
            );
×
53

54
            $value = $this->checkConvertedValue((string)$value, $platform, $converted !== false ? $converted : null);
×
55
        }
56

57
        return parent::convertToPHPValue($value, $platform);
×
58
    }
59

60
    /**
61
     * Method to initialize DateTimeZone as in UTC.
62
     */
63
    private function getUtcDateTimeZone(): DateTimeZone
64
    {
65
        return self::$utc ??= new DateTimeZone('UTC');
×
66
    }
67

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

79
        throw ConversionException::conversionFailedFormat(
×
80
            $value,
×
81
            $this->getName(),
×
82
            $platform->getDateTimeFormatString()
×
83
        );
×
84
    }
85
}
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