From b7cc086ae13df85aa5325c7d7fe0ae0033785c43 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sun, 6 Oct 2024 20:18:32 +0200 Subject: [PATCH] fix php generics --- src/Generator/Php.php | 7 ++++--- src/Generator/Type/Php.php | 2 +- tests/Generator/resource/php/php_oop.php | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Generator/Php.php b/src/Generator/Php.php index 6f3e83d6..ced3b20a 100644 --- a/src/Generator/Php.php +++ b/src/Generator/Php.php @@ -93,6 +93,10 @@ protected function writeStruct(Code\Name $name, array $properties, ?string $exte $tags['template'] = $generics; } + if (!empty($templates)) { + $tags['extends'] = $extends . $this->generator->getGenericType($templates); + } + $uses = []; $class = $this->factory->class($name->getClass()); @@ -109,9 +113,6 @@ protected function writeStruct(Code\Name $name, array $properties, ?string $exte } if (!empty($extends)) { - if (!empty($templates)) { - $extends.= $this->generator->getGenericType($templates); - } $class->extend($extends); } diff --git a/src/Generator/Type/Php.php b/src/Generator/Type/Php.php index a7967a92..ed3d30c3 100644 --- a/src/Generator/Type/Php.php +++ b/src/Generator/Type/Php.php @@ -123,7 +123,7 @@ protected function getGroup(string $type): string protected function getGeneric(array $types): string { - return ''; + return '<' . implode(', ', $types) . '>'; } protected function getAny(): string diff --git a/tests/Generator/resource/php/php_oop.php b/tests/Generator/resource/php/php_oop.php index 2368e562..8612a696 100644 --- a/tests/Generator/resource/php/php_oop.php +++ b/tests/Generator/resource/php/php_oop.php @@ -102,6 +102,9 @@ public function jsonSerialize() : object } } +/** + * @extends Map + */ class StudentMap extends Map implements \JsonSerializable, \PSX\Record\RecordableInterface { }