Skip to content

Commit 2f580c9

Browse files
committed
Declare nativeType of parent property explicitly as workaround for bug in symfony TypeInfo
Symfony/type-info returns an invalid property type for the parent property based on the @phpstan-var static phpdoc in the parent. It returns some App\Entity\Base\AttachmentType which does not exists. Symfony issue: symfony/symfony#62922
1 parent 402edf0 commit 2f580c9

10 files changed

Lines changed: 30 additions & 10 deletions

File tree

src/Entity/Attachments/AttachmentType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
use Doctrine\Common\Collections\Collection;
4848
use Doctrine\ORM\Mapping as ORM;
4949
use Symfony\Component\Serializer\Annotation\Groups;
50+
use Symfony\Component\TypeInfo\Type\NullableType;
51+
use Symfony\Component\TypeInfo\Type\ObjectType;
5052
use Symfony\Component\Validator\Constraints as Assert;
5153

5254
/**
@@ -93,7 +95,7 @@ class AttachmentType extends AbstractStructuralDBElement
9395
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'children')]
9496
#[ORM\JoinColumn(name: 'parent_id')]
9597
#[Groups(['attachment_type:read', 'attachment_type:write'])]
96-
#[ApiProperty(readableLink: true, writableLink: false)]
98+
#[ApiProperty(readableLink: true, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
9799
protected ?AbstractStructuralDBElement $parent = null;
98100

99101
/**

src/Entity/Parts/Category.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
use Doctrine\Common\Collections\Collection;
5151
use Doctrine\ORM\Mapping as ORM;
5252
use Symfony\Component\Serializer\Annotation\Groups;
53+
use Symfony\Component\TypeInfo\Type\NullableType;
54+
use Symfony\Component\TypeInfo\Type\ObjectType;
5355
use Symfony\Component\Validator\Constraints as Assert;
5456

5557
/**
@@ -98,7 +100,7 @@ class Category extends AbstractPartsContainingDBElement
98100
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
99101
#[ORM\JoinColumn(name: 'parent_id')]
100102
#[Groups(['category:read', 'category:write'])]
101-
#[ApiProperty(readableLink: false, writableLink: false)]
103+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
102104
protected ?AbstractStructuralDBElement $parent = null;
103105

104106
#[Groups(['category:read', 'category:write'])]

src/Entity/Parts/Footprint.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
use Doctrine\Common\Collections\Collection;
5050
use Doctrine\ORM\Mapping as ORM;
5151
use Symfony\Component\Serializer\Annotation\Groups;
52+
use Symfony\Component\TypeInfo\Type\NullableType;
53+
use Symfony\Component\TypeInfo\Type\ObjectType;
5254
use Symfony\Component\Validator\Constraints as Assert;
5355

5456
/**
@@ -93,7 +95,7 @@ class Footprint extends AbstractPartsContainingDBElement
9395
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
9496
#[ORM\JoinColumn(name: 'parent_id')]
9597
#[Groups(['footprint:read', 'footprint:write'])]
96-
#[ApiProperty(readableLink: false, writableLink: false)]
98+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
9799
protected ?AbstractStructuralDBElement $parent = null;
98100

99101
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]

src/Entity/Parts/Manufacturer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
use Doctrine\Common\Collections\Collection;
4949
use Doctrine\ORM\Mapping as ORM;
5050
use Symfony\Component\Serializer\Annotation\Groups;
51+
use Symfony\Component\TypeInfo\Type\NullableType;
52+
use Symfony\Component\TypeInfo\Type\ObjectType;
5153
use Symfony\Component\Validator\Constraints as Assert;
5254

5355
/**
@@ -92,7 +94,7 @@ class Manufacturer extends AbstractCompany
9294
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
9395
#[ORM\JoinColumn(name: 'parent_id')]
9496
#[Groups(['manufacturer:read', 'manufacturer:write'])]
95-
#[ApiProperty(readableLink: false, writableLink: false)]
97+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
9698
protected ?AbstractStructuralDBElement $parent = null;
9799

98100
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]

src/Entity/Parts/MeasurementUnit.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
use Doctrine\ORM\Mapping as ORM;
5151
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
5252
use Symfony\Component\Serializer\Annotation\Groups;
53+
use Symfony\Component\TypeInfo\Type\NullableType;
54+
use Symfony\Component\TypeInfo\Type\ObjectType;
5355
use Symfony\Component\Validator\Constraints as Assert;
5456
use Symfony\Component\Validator\Constraints\Length;
5557

@@ -130,7 +132,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
130132
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
131133
#[ORM\JoinColumn(name: 'parent_id')]
132134
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
133-
#[ApiProperty(readableLink: false, writableLink: false)]
135+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
134136
protected ?AbstractStructuralDBElement $parent = null;
135137

136138
/**

src/Entity/Parts/PartCustomState.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
use Doctrine\Common\Collections\Criteria;
4747
use Doctrine\ORM\Mapping as ORM;
4848
use Symfony\Component\Serializer\Annotation\Groups;
49+
use Symfony\Component\TypeInfo\Type\NullableType;
50+
use Symfony\Component\TypeInfo\Type\ObjectType;
4951
use Symfony\Component\Validator\Constraints as Assert;
5052

5153
/**
@@ -87,7 +89,7 @@ class PartCustomState extends AbstractPartsContainingDBElement
8789
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
8890
#[ORM\JoinColumn(name: 'parent_id')]
8991
#[Groups(['part_custom_state:read', 'part_custom_state:write'])]
90-
#[ApiProperty(readableLink: false, writableLink: false)]
92+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
9193
protected ?AbstractStructuralDBElement $parent = null;
9294

9395
/**

src/Entity/Parts/StorageLocation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
use Doctrine\Common\Collections\Collection;
5151
use Doctrine\ORM\Mapping as ORM;
5252
use Symfony\Component\Serializer\Annotation\Groups;
53+
use Symfony\Component\TypeInfo\Type\NullableType;
54+
use Symfony\Component\TypeInfo\Type\ObjectType;
5355
use Symfony\Component\Validator\Constraints as Assert;
5456

5557
/**
@@ -97,7 +99,7 @@ class StorageLocation extends AbstractPartsContainingDBElement
9799
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
98100
#[ORM\JoinColumn(name: 'parent_id')]
99101
#[Groups(['location:read', 'location:write'])]
100-
#[ApiProperty(readableLink: false, writableLink: false)]
102+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
101103
protected ?AbstractStructuralDBElement $parent = null;
102104

103105
#[Groups(['location:read', 'location:write'])]

src/Entity/Parts/Supplier.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
use Doctrine\Common\Collections\Collection;
5454
use Doctrine\ORM\Mapping as ORM;
5555
use Symfony\Component\Serializer\Annotation\Groups;
56+
use Symfony\Component\TypeInfo\Type\NullableType;
57+
use Symfony\Component\TypeInfo\Type\ObjectType;
5658
use Symfony\Component\Validator\Constraints as Assert;
5759

5860
/**
@@ -99,7 +101,7 @@ class Supplier extends AbstractCompany
99101
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
100102
#[ORM\JoinColumn(name: 'parent_id')]
101103
#[Groups(['supplier:read', 'supplier:write'])]
102-
#[ApiProperty(readableLink: false, writableLink: false)]
104+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
103105
protected ?AbstractStructuralDBElement $parent = null;
104106

105107
/**

src/Entity/PriceInformations/Currency.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
use Doctrine\ORM\Mapping as ORM;
5353
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
5454
use Symfony\Component\Serializer\Annotation\Groups;
55+
use Symfony\Component\TypeInfo\Type\NullableType;
56+
use Symfony\Component\TypeInfo\Type\ObjectType;
5557
use Symfony\Component\Validator\Constraints as Assert;
5658

5759
/**
@@ -125,7 +127,7 @@ class Currency extends AbstractStructuralDBElement
125127
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
126128
#[ORM\JoinColumn(name: 'parent_id')]
127129
#[Groups(['currency:read', 'currency:write'])]
128-
#[ApiProperty(readableLink: false, writableLink: false)]
130+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
129131
protected ?AbstractStructuralDBElement $parent = null;
130132

131133
/**

src/Entity/ProjectSystem/Project.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
use Doctrine\ORM\Mapping as ORM;
5050
use InvalidArgumentException;
5151
use Symfony\Component\Serializer\Annotation\Groups;
52+
use Symfony\Component\TypeInfo\Type\NullableType;
53+
use Symfony\Component\TypeInfo\Type\ObjectType;
5254
use Symfony\Component\Validator\Constraints as Assert;
5355
use Symfony\Component\Validator\Context\ExecutionContextInterface;
5456

@@ -95,7 +97,7 @@ class Project extends AbstractStructuralDBElement
9597
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
9698
#[ORM\JoinColumn(name: 'parent_id')]
9799
#[Groups(['project:read', 'project:write'])]
98-
#[ApiProperty(readableLink: false, writableLink: false)]
100+
#[ApiProperty(readableLink: false, writableLink: false, nativeType: new NullableType(new ObjectType(self::class)))]
99101
protected ?AbstractStructuralDBElement $parent = null;
100102

101103
#[Groups(['project:read', 'project:write'])]

0 commit comments

Comments
 (0)