Skip to content

Commit

Permalink
fix php generics
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 6, 2024
1 parent db24a1c commit b7cc086
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Generator/Php.php
Original file line number Diff line number Diff line change
@@ -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);
}

2 changes: 1 addition & 1 deletion src/Generator/Type/Php.php
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ protected function getGroup(string $type): string

protected function getGeneric(array $types): string
{
return '';
return '<' . implode(', ', $types) . '>';
}

protected function getAny(): string
3 changes: 3 additions & 0 deletions tests/Generator/resource/php/php_oop.php
Original file line number Diff line number Diff line change
@@ -102,6 +102,9 @@ public function jsonSerialize() : object
}
}

/**
* @extends Map<Student>
*/
class StudentMap extends Map implements \JsonSerializable, \PSX\Record\RecordableInterface
{
}

0 comments on commit b7cc086

Please sign in to comment.