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

nextras / orm / 41909495460

04 Nov 2026 08:44PM UTC coverage: 92.015% (-0.002%) from 92.017%
41909495460

push

github

web-flow
Merge pull request #842 from nextras/js/dresscode

Setup DressCode

288 of 347 new or added lines in 66 files covered. (83.0%)

14 existing lines in 9 files now uncovered.

4402 of 4784 relevant lines covered (92.02%)

6.29 hits per line

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

91.67
/src/Entity/PropertyWrapper/DateWrapper.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Entity\PropertyWrapper;
4

5

6
use Nextras\Dbal\Utils\DateTimeImmutable;
7
use Nextras\Orm\Entity\ImmutableValuePropertyWrapper;
8
use Nextras\Orm\Entity\PropertyComparator;
9
use Nextras\Orm\Exception\InvalidPropertyValueException;
10
use Nextras\Orm\Exception\NullValueException;
11

12

13
/**
14
 * \DateTimeImmutable property wrapper for DATE only representation.
15
 *
16
 * Handles auto-conversion from string (e.g., YYYY-MM-DD - a local date, but also other formats accepted
17
 * by \DateTimeImmutable constructor), and DateTimeInterface instances to \DateTimeImmutable (sub-)type.
18
 */
19
class DateWrapper extends ImmutableValuePropertyWrapper implements PropertyComparator
20
{
21
        public function convertToRawValue(mixed $value): mixed
22
        {
23
                /** @var class-string<covariant DateTimeImmutable> $rawType */
24
                $rawType = array_key_first($this->propertyMetadata->types);
7 ✔
25

26
                if ($value instanceof $rawType) {
7 ✔
27
                        /** @noinspection PhpSillyAssignmentInspection */
28
                        $value = $value;
7 ✔
29
                } elseif ($value instanceof \DateTimeInterface) {
7 ✔
30
                        $value = new $rawType($value->format('c'));
7 ✔
31
                } elseif ($value === null) {
7 ✔
32
                        return null;
7 ✔
33
                } elseif (is_string($value)) {
7 ✔
34
                        if ($value === '') throw new InvalidPropertyValueException($this->propertyMetadata);
7 ✔
35

36
                        $tmp = new $rawType($value);
7 ✔
37
                        $value = $tmp->setTimezone(new \DateTimeZone(date_default_timezone_get()));
7 ✔
38
                } else {
UNCOV
39
                        throw new InvalidPropertyValueException($this->propertyMetadata);
×
40
                }
41

42
                return $value->setTime(0, 0);
7 ✔
43
        }
44

45

46
        public function convertFromRawValue($value)
47
        {
48
                // The string conversion from raw values is used when using {default} modifier in property definition.
49
                // This string value is considered to be a raw value.
50
                if (is_string($value)) {
7 ✔
51
                        if ($value === '') throw new InvalidPropertyValueException($this->propertyMetadata);
7 ✔
52

53
                        /** @var class-string<covariant DateTimeImmutable> $rawType */
54
                        $rawType = array_key_first($this->propertyMetadata->types);
7 ✔
55
                        $tmp = new $rawType($value);
7 ✔
56
                        $value = $tmp->setTimezone(new \DateTimeZone(date_default_timezone_get()));
7 ✔
57
                }
58

59
                return $value?->setTime(0, 0);
7 ✔
60
        }
61

62

63
        public function setInjectedValue($value): bool
64
        {
65
                if ($value === null && !$this->propertyMetadata->isNullable) {
7 ✔
66
                        throw new NullValueException($this->propertyMetadata);
×
67
                }
68
                return parent::setInjectedValue($this->convertToRawValue($value));
7 ✔
69
        }
70

71

72
        public function equals(mixed $a, mixed $b): bool
73
        {
74
                assert($a === null || $a instanceof \DateTimeImmutable);
75
                assert($b === null || $b instanceof \DateTimeImmutable);
76
                return $a?->getTimestamp() === $b?->getTimestamp();
7 ✔
77
        }
78

79

80
        public function compare(mixed $a, mixed $b): int
81
        {
82
                assert($a === null || $a instanceof \DateTimeImmutable);
83
                assert($b === null || $b instanceof \DateTimeImmutable);
84
                return $a?->getTimestamp() <=> $b?->getTimestamp();
7 ✔
85
        }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc