Skip to content

Commit 24428da

Browse files
authored
fix: only one extends should be generated (#357)
1 parent 037f5c0 commit 24428da

File tree

5 files changed

+9
-35
lines changed

5 files changed

+9
-35
lines changed

src/Model/Class_.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,13 @@ public function toNetteFile(array $config, Inflector $inflector, ?PhpFile $file
311311
$class->setImplements($implements);
312312
}
313313

314-
if ($this->parent()) {
314+
if ($this->parent() && !$class->getExtends()) {
315315
$parentExtend = $this->resolveName($namespace, $this->parent());
316316
if ($this->isParentEnum()) {
317317
$parentExtend = MyCLabsEnum::class;
318318
}
319-
$extends = (array) $class->getExtends();
320-
if (!\in_array($parentExtend, $extends, true)) {
321-
$extends[] = $parentExtend;
322-
}
323-
$class->setExtends($extends);
319+
320+
$class->setExtends($parentExtend);
324321
}
325322

326323
$netteConstants = $class->getConstants();

tests/e2e/customized/App/Entity/Thing.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@
55
namespace App\Entity;
66

77
use ApiPlatform\Core\Annotation\ApiProperty;
8-
use ApiPlatform\Core\Annotation\ApiResource;
98
use Doctrine\ORM\Mapping as ORM;
109

1110
/**
1211
* The most generic type of item.
1312
*
1413
* @see https://schema.org/Thing
1514
*/
16-
#[ORM\Entity]
17-
#[ApiResource(iri: 'https://schema.org/Thing')]
18-
class Thing
15+
#[ORM\MappedSuperclass]
16+
abstract class Thing
1917
{
20-
#[ORM\Id]
21-
#[ORM\GeneratedValue(strategy: 'AUTO')]
22-
#[ORM\Column(type: 'integer')]
23-
private ?int $id = null;
24-
2518
/**
2619
* The name of the item.
2720
*
@@ -31,11 +24,6 @@ class Thing
3124
#[ApiProperty(iri: 'https://schema.org/name')]
3225
private ?string $name = null;
3326

34-
public function getId(): ?int
35-
{
36-
return $this->id;
37-
}
38-
3927
public function setName(?string $name): void
4028
{
4129
$this->name = $name;

tests/e2e/original/App/Entity/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
collectionOperations: ['get' => ['route_name' => 'get_person_collection']],
2525
)]
2626
#[UniqueEntity('email')]
27-
class Person
27+
class Person extends Thing
2828
{
2929
#[ORM\Id]
3030
#[ORM\GeneratedValue(strategy: 'AUTO')]

tests/e2e/original/App/Entity/Thing.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@
55
namespace App\Entity;
66

77
use ApiPlatform\Core\Annotation\ApiProperty;
8-
use ApiPlatform\Core\Annotation\ApiResource;
98
use Doctrine\ORM\Mapping as ORM;
109

1110
/**
1211
* The most generic type of item.
1312
*
1413
* @see https://schema.org/Thing
1514
*/
16-
#[ORM\Entity]
17-
#[ApiResource(iri: 'https://schema.org/Thing')]
18-
class Thing
15+
#[ORM\MappedSuperclass]
16+
abstract class Thing
1917
{
20-
#[ORM\Id]
21-
#[ORM\GeneratedValue(strategy: 'AUTO')]
22-
#[ORM\Column(type: 'integer')]
23-
private ?int $id = null;
24-
2518
/**
2619
* The name of the item.
2720
*
@@ -31,11 +24,6 @@ class Thing
3124
#[ApiProperty(iri: 'https://schema.org/name')]
3225
private ?string $name = null;
3326

34-
public function getId(): ?int
35-
{
36-
return $this->id;
37-
}
38-
3927
public function setName(?string $name): void
4028
{
4129
$this->name = $name;

tests/e2e/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ types:
77
properties:
88
name: ~
99
Person:
10+
parent: ~
1011
operations:
1112
item:
1213
get:

0 commit comments

Comments
 (0)