Skip to content

Commit 24312c3

Browse files
Sander van der Vlugtsvandervlugt
authored andcommitted
Support more doctrine types
1 parent 7c12c19 commit 24312c3

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/AnnotationProcessor/DoctrineAnnotationProcessor.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function transformType($type)
231231
return 'string';
232232
}
233233

234-
if ($type === Types::BLOB /* binary will be added in doctrine 2.5 */) {
234+
if ($type === Types::BLOB || $type === Types::BINARY) {
235235
return 'resource';
236236
}
237237

@@ -250,6 +250,23 @@ private function transformType($type)
250250
return '\\' . \DateTime::class;
251251
}
252252

253+
if (\in_array(
254+
$type,
255+
[
256+
Types::DATETIME_IMMUTABLE,
257+
Types::DATE_IMMUTABLE,
258+
Types::DATETIMETZ_IMMUTABLE,
259+
Types::TIME_IMMUTABLE,
260+
],
261+
true
262+
)) {
263+
return '\\' . \DateTimeImmutable::class;
264+
}
265+
266+
if ($type === Types::DATEINTERVAL) {
267+
return '\\' . \DateInterval::class;
268+
}
269+
253270
if (\in_array(
254271
$type,
255272
[Types::SIMPLE_ARRAY, self::JSON_ARRAY, Types::JSON, Types::ARRAY, self::YAML_ARRAY],

test/AnnotationProcessor/DoctrineAnnotationProcessorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,20 @@ public function typeConversionDataProvider(): array
264264
['datetimetz', '\\DateTime'],
265265
['zeroeddatetime', '\\DateTime'],
266266
['zeroeddate', '\\DateTime'],
267+
['dateinterval', '\\DateInterval'],
267268
['array', 'array'],
268269
['json_array', 'array'],
269270
['json', 'array'],
270271
['object', 'object'],
272+
['binary', 'resource'],
271273
['double', null, \DomainException::class],
272274
['bool', null, \DomainException::class],
273-
['binary', null, \DomainException::class],
274275
['int', null, \DomainException::class],
275276
['', null, \DomainException::class],
277+
['datetime_immutable', '\\DateTimeImmutable'],
278+
['date_immutable', '\\DateTimeImmutable'],
279+
['datetimetz_immutable', '\\DateTimeImmutable'],
280+
['time_immutable', '\\DateTimeImmutable'],
276281
];
277282
}
278283

0 commit comments

Comments
 (0)