From dae402060c65a92da54b9f6962146fc54639f35b Mon Sep 17 00:00:00 2001 From: Vitor de Souza Date: Tue, 7 May 2024 06:16:56 -0300 Subject: [PATCH] fix DateTimeInterface missing from php 8.1+ --- CHANGELOG.md | 4 ++++ src/Generator/MutatorAccessorClassGeneratorAbstract.php | 5 ----- src/Generator/RequestGenerator.php | 4 ++++ src/Generator/SchemaGenerator.php | 4 ++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ce12a..8af72d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [10.7.1] - 2024.05.07 +### Fixed +- Missing DateTimeInterface import for php 8.1+ + ## [10.7.0] - 2024.02.15 ### Added - Added support for php 8.1, 8.2, 8.3 constraints diff --git a/src/Generator/MutatorAccessorClassGeneratorAbstract.php b/src/Generator/MutatorAccessorClassGeneratorAbstract.php index 9622066..d05b670 100644 --- a/src/Generator/MutatorAccessorClassGeneratorAbstract.php +++ b/src/Generator/MutatorAccessorClassGeneratorAbstract.php @@ -4,7 +4,6 @@ namespace DoclerLabs\ApiClientGenerator\Generator; -use DateTimeInterface; use DoclerLabs\ApiClientException\RequestValidationException; use DoclerLabs\ApiClientGenerator\Ast\Builder\CodeBuilder; use DoclerLabs\ApiClientGenerator\Entity\Constraint\ConstraintInterface; @@ -81,10 +80,6 @@ protected function generateGet(Field $field): ClassMethod protected function generateProperty(Field $field): Property { - if ($field->isDate()) { - $this->addImport(DateTimeInterface::class); - } - return $this->builder->localProperty( $field->getPhpVariableName(), $field->getPhpTypeHint(), diff --git a/src/Generator/RequestGenerator.php b/src/Generator/RequestGenerator.php index d78d970..2c209a3 100644 --- a/src/Generator/RequestGenerator.php +++ b/src/Generator/RequestGenerator.php @@ -4,6 +4,7 @@ namespace DoclerLabs\ApiClientGenerator\Generator; +use DateTimeInterface; use DoclerLabs\ApiClientGenerator\Ast\Builder\CodeBuilder; use DoclerLabs\ApiClientGenerator\Ast\Builder\ParameterBuilder; use DoclerLabs\ApiClientGenerator\Ast\ParameterNode; @@ -103,6 +104,9 @@ protected function generateProperties(Request $request, Operation $operation, Sp ) ); } + if ($field->isDate()) { + $this->addImport(DateTimeInterface::class); + } if ( $field->isRequired() && $this->phpVersion->isConstructorPropertyPromotionSupported() diff --git a/src/Generator/SchemaGenerator.php b/src/Generator/SchemaGenerator.php index cef4639..4c545f9 100644 --- a/src/Generator/SchemaGenerator.php +++ b/src/Generator/SchemaGenerator.php @@ -4,6 +4,7 @@ namespace DoclerLabs\ApiClientGenerator\Generator; +use DateTimeInterface; use DoclerLabs\ApiClientGenerator\Ast\Builder\ParameterBuilder; use DoclerLabs\ApiClientGenerator\Ast\ParameterNode; use DoclerLabs\ApiClientGenerator\Entity\Field; @@ -108,6 +109,9 @@ protected function generateProperties(Field $root): array { $statements = []; foreach ($root->getObjectProperties() as $propertyField) { + if ($propertyField->isDate()) { + $this->addImport(DateTimeInterface::class); + } if ( $propertyField->isRequired() && $this->phpVersion->isConstructorPropertyPromotionSupported()