Skip to content

Commit

Permalink
fix: Fixed Collection type hinting and co-variance
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed May 19, 2023
1 parent cd1b21e commit 2a53d81
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 126 deletions.
4 changes: 2 additions & 2 deletions lib/Documents/src/Models/HasThumbnailInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function getOriginal(): ?HasThumbnailInterface;
public function setOriginal(?HasThumbnailInterface $original): static;

/**
* @return Collection<int, static>
* @return Collection<int, DocumentInterface>
*/
public function getThumbnails(): Collection;

/**
* @param Collection<int, static> $thumbnails
* @param Collection<int, DocumentInterface> $thumbnails
* @return $this
*/
public function setThumbnails(Collection $thumbnails): static;
Expand Down
4 changes: 2 additions & 2 deletions lib/RoadizCoreBundle/src/Api/Dto/DocumentOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace RZ\Roadiz\CoreBundle\Api\Dto;

use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Folder;
use RZ\Roadiz\Documents\Models\DocumentInterface;
use RZ\Roadiz\Documents\Models\FolderInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;

Expand Down Expand Up @@ -91,7 +91,7 @@ final class DocumentOutput
#[Groups(['document', 'document_display'])]
public ?Document $thumbnail = null;
/**
* @var array<Folder>
* @var array<FolderInterface>
*/
#[Groups(['document_folders'])]
public array $folders = [];
Expand Down
8 changes: 4 additions & 4 deletions lib/RoadizCoreBundle/src/Entity/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Attribute extends AbstractEntity implements AttributeInterface
use AttributeTrait;

/**
* @var Collection<AttributeDocuments>
* @var Collection<int, AttributeDocuments>
*/
#[
ORM\OneToMany(
Expand All @@ -57,7 +57,7 @@ public function __construct()
}

/**
* @return Collection<AttributeDocuments>
* @return Collection<int, AttributeDocuments>
*/
public function getAttributeDocuments(): Collection
{
Expand All @@ -77,7 +77,7 @@ public function setAttributeDocuments(Collection $attributeDocuments): Attribute
}

/**
* @return Collection<Document>
* @return Collection<int, Document>
*/
#[
Serializer\VirtualProperty(),
Expand All @@ -86,7 +86,7 @@ public function setAttributeDocuments(Collection $attributeDocuments): Attribute
]
public function getDocuments(): Collection
{
/** @var Collection<Document> $values */
/** @var Collection<int, Document> $values */
$values = $this->attributeDocuments->map(function (AttributeDocuments $attributeDocuments) {
return $attributeDocuments->getDocument();
})->filter(function (?Document $document) {
Expand Down
6 changes: 3 additions & 3 deletions lib/RoadizCoreBundle/src/Entity/CustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CustomForm extends AbstractDateTimed
private ?DateTime $closeDate = null;

/**
* @var Collection<CustomFormField>
* @var Collection<int, CustomFormField>
*/
#[
ORM\OneToMany(mappedBy: "customForm", targetEntity: CustomFormField::class, cascade: ["ALL"]),
Expand All @@ -113,7 +113,7 @@ class CustomForm extends AbstractDateTimed
private Collection $fields;

/**
* @var Collection<CustomFormAnswer>
* @var Collection<int, CustomFormAnswer>
*/
#[
ORM\OneToMany(
Expand All @@ -127,7 +127,7 @@ class CustomForm extends AbstractDateTimed
private Collection $customFormAnswers;

/**
* @var Collection<NodesCustomForms>
* @var Collection<int, NodesCustomForms>
*/
#[
ORM\OneToMany(mappedBy: "customForm", targetEntity: NodesCustomForms::class, fetch: "EXTRA_LAZY"),
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Entity/CustomFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CustomFormField extends AbstractField
private ?CustomForm $customForm = null;

/**
* @var Collection<CustomFormFieldAttribute>
* @var Collection<int, CustomFormFieldAttribute>
*/
#[
ORM\OneToMany(mappedBy: "customFormField", targetEntity: CustomFormFieldAttribute::class),
Expand Down
44 changes: 23 additions & 21 deletions lib/RoadizCoreBundle/src/Entity/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,42 +134,42 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
#[Serializer\Type('string')]
protected ?string $embedPlatform = null;
/**
* @var Collection<NodesSourcesDocuments>
* @var Collection<int, NodesSourcesDocuments>
*/
#[ORM\OneToMany(mappedBy: 'document', targetEntity: NodesSourcesDocuments::class)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
protected Collection $nodesSourcesByFields;
/**
* @var Collection<TagTranslationDocuments>
* @var Collection<int, TagTranslationDocuments>
*/
#[ORM\OneToMany(mappedBy: 'document', targetEntity: TagTranslationDocuments::class)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
protected Collection $tagTranslations;
/**
* @var Collection<AttributeDocuments>
* @var Collection<int, AttributeDocuments>
*/
#[ORM\OneToMany(mappedBy: 'document', targetEntity: AttributeDocuments::class)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
protected Collection $attributeDocuments;
/**
* @var Collection<CustomFormFieldAttribute>
* @var Collection<int, CustomFormFieldAttribute>
*/
#[ORM\ManyToMany(targetEntity: CustomFormFieldAttribute::class, mappedBy: 'documents')]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
protected Collection $customFormFieldAttributes;
/**
* @var Collection<Folder>
* @var Collection<int, FolderInterface>
*/
#[ORM\JoinTable(name: 'documents_folders')]
#[ORM\ManyToMany(targetEntity: Folder::class, mappedBy: 'documents')]
#[SymfonySerializer\Ignore]
protected Collection $folders;
/**
* @var Collection<DocumentTranslation>
* @var Collection<int, DocumentTranslation>
*/
#[ORM\OneToMany(
mappedBy: 'document',
Expand Down Expand Up @@ -201,7 +201,7 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
#[Serializer\Type('string')]
private ?string $mimeType = null;
/**
* @var Collection<DocumentInterface>
* @var Collection<int, DocumentInterface>
*/
#[ORM\OneToMany(mappedBy: 'rawDocument', targetEntity: Document::class, fetch: 'EXTRA_LAZY')]
#[SymfonySerializer\Ignore]
Expand Down Expand Up @@ -265,7 +265,7 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
private ?int $filesize = null;

/**
* @var Collection<Document>
* @var Collection<int, DocumentInterface>
*/
#[ORM\OneToMany(mappedBy: 'original', targetEntity: Document::class, fetch: 'EXTRA_LAZY')]
#[SymfonySerializer\Ignore]
Expand All @@ -274,7 +274,7 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
private Collection $thumbnails;

/**
* @var Document|null
* @var HasThumbnailInterface|null
*/
#[ORM\ManyToOne(targetEntity: Document::class, fetch: 'EXTRA_LAZY', inversedBy: 'thumbnails')]
#[ORM\JoinColumn(name: 'original', nullable: true, onDelete: 'SET NULL')]
Expand All @@ -283,7 +283,7 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
#[Serializer\Groups(['document_original'])]
#[Serializer\MaxDepth(1)]
#[Serializer\Type('RZ\Roadiz\CoreBundle\Entity\Document')]
private ?DocumentInterface $original = null;
private ?HasThumbnailInterface $original = null;

public function __construct()
{
Expand Down Expand Up @@ -358,7 +358,7 @@ public function setRawDocument(DocumentInterface $rawDocument = null): static
}

/**
* @return Collection<NodesSourcesDocuments>
* @return Collection<int, NodesSourcesDocuments>
*/
#[SymfonySerializer\Ignore]
public function getNodesSourcesByFields(): Collection
Expand All @@ -367,7 +367,7 @@ public function getNodesSourcesByFields(): Collection
}

/**
* @return Collection<TagTranslationDocuments>
* @return Collection<int, TagTranslationDocuments>
*/
#[SymfonySerializer\Ignore]
public function getTagTranslations(): Collection
Expand All @@ -376,7 +376,7 @@ public function getTagTranslations(): Collection
}

/**
* @return Collection<AttributeDocuments>
* @return Collection<int, AttributeDocuments>
*/
#[SymfonySerializer\Ignore]
public function getAttributeDocuments(): Collection
Expand All @@ -395,7 +395,7 @@ public function addFolder(FolderInterface $folder): static
}

/**
* @return Collection<Folder>
* @return Collection<int, FolderInterface>
*/
#[SymfonySerializer\Ignore]
public function getFolders(): Collection
Expand All @@ -422,7 +422,7 @@ public function removeFolder(FolderInterface $folder): static

/**
* @param TranslationInterface $translation
* @return Collection<DocumentTranslation>
* @return Collection<int, DocumentTranslation>
*/
#[SymfonySerializer\Ignore]
public function getDocumentTranslationsByTranslation(TranslationInterface $translation): Collection
Expand All @@ -447,7 +447,7 @@ public function addDocumentTranslation(DocumentTranslation $documentTranslation)
}

/**
* @return Collection<DocumentTranslation>
* @return Collection<int, DocumentTranslation>
*/
public function getDocumentTranslations(): Collection
{
Expand Down Expand Up @@ -649,17 +649,19 @@ public function getThumbnails(): Collection
public function setThumbnails(Collection $thumbnails): static
{
if ($this->thumbnails->count()) {
/** @var HasThumbnailInterface $thumbnail */
foreach ($this->thumbnails as $thumbnail) {
$thumbnail->setOriginal(null);
if ($thumbnail instanceof HasThumbnailInterface) {
$thumbnail->setOriginal(null);
}
}
}
$this->thumbnails = $thumbnails->filter(function (HasThumbnailInterface $thumbnail) {
$this->thumbnails = $thumbnails->filter(function (DocumentInterface $thumbnail) {
return $thumbnail !== $this;
});
/** @var HasThumbnailInterface $thumbnail */
foreach ($this->thumbnails as $thumbnail) {
$thumbnail->setOriginal($this);
if ($thumbnail instanceof HasThumbnailInterface) {
$thumbnail->setOriginal($this);
}
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions lib/RoadizCoreBundle/src/Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Group extends AbstractEntity
private string $name = '';

/**
* @var Collection<User>
* @var Collection<int, User>
*/
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'groups')]
#[SymfonySerializer\Groups(['group_user'])]
Expand All @@ -41,7 +41,7 @@ class Group extends AbstractEntity
private Collection $users;

/**
* @var Collection<Role>
* @var Collection<int, Role>
*/
#[ORM\JoinTable(name: 'groups_roles')]
#[ORM\JoinColumn(name: 'group_id', referencedColumnName: 'id')]
Expand Down
Loading

0 comments on commit 2a53d81

Please sign in to comment.