Skip to content

Commit 84f5211

Browse files
authored
Merge pull request #111 from DoclerLabs/fix-datetimeinterface-php81
fix DateTimeInterface missing from php 8.1+
2 parents 8eaf0ab + dae4020 commit 84f5211

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [10.7.1] - 2024.05.07
8+
### Fixed
9+
- Missing DateTimeInterface import for php 8.1+
10+
711
## [10.7.0] - 2024.02.15
812
### Added
913
- Added support for php 8.1, 8.2, 8.3 constraints

src/Generator/MutatorAccessorClassGeneratorAbstract.php

-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace DoclerLabs\ApiClientGenerator\Generator;
66

7-
use DateTimeInterface;
87
use DoclerLabs\ApiClientException\RequestValidationException;
98
use DoclerLabs\ApiClientGenerator\Ast\Builder\CodeBuilder;
109
use DoclerLabs\ApiClientGenerator\Entity\Constraint\ConstraintInterface;
@@ -81,10 +80,6 @@ protected function generateGet(Field $field): ClassMethod
8180

8281
protected function generateProperty(Field $field): Property
8382
{
84-
if ($field->isDate()) {
85-
$this->addImport(DateTimeInterface::class);
86-
}
87-
8883
return $this->builder->localProperty(
8984
$field->getPhpVariableName(),
9085
$field->getPhpTypeHint(),

src/Generator/RequestGenerator.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace DoclerLabs\ApiClientGenerator\Generator;
66

7+
use DateTimeInterface;
78
use DoclerLabs\ApiClientGenerator\Ast\Builder\CodeBuilder;
89
use DoclerLabs\ApiClientGenerator\Ast\Builder\ParameterBuilder;
910
use DoclerLabs\ApiClientGenerator\Ast\ParameterNode;
@@ -103,6 +104,9 @@ protected function generateProperties(Request $request, Operation $operation, Sp
103104
)
104105
);
105106
}
107+
if ($field->isDate()) {
108+
$this->addImport(DateTimeInterface::class);
109+
}
106110
if (
107111
$field->isRequired()
108112
&& $this->phpVersion->isConstructorPropertyPromotionSupported()

src/Generator/SchemaGenerator.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace DoclerLabs\ApiClientGenerator\Generator;
66

7+
use DateTimeInterface;
78
use DoclerLabs\ApiClientGenerator\Ast\Builder\ParameterBuilder;
89
use DoclerLabs\ApiClientGenerator\Ast\ParameterNode;
910
use DoclerLabs\ApiClientGenerator\Entity\Field;
@@ -108,6 +109,9 @@ protected function generateProperties(Field $root): array
108109
{
109110
$statements = [];
110111
foreach ($root->getObjectProperties() as $propertyField) {
112+
if ($propertyField->isDate()) {
113+
$this->addImport(DateTimeInterface::class);
114+
}
111115
if (
112116
$propertyField->isRequired()
113117
&& $this->phpVersion->isConstructorPropertyPromotionSupported()

0 commit comments

Comments
 (0)